这个错误是什么意思?(50分)

L

lizheng

Unregistered / Unconfirmed
GUEST, unregistred user!

Project Project1.exe raised edception

class EAccessViolatio with

message 'Access violation at

address 4CEOOC5B in module

'IDPDX32.DLL'.Read of address FFFFFFFF'.

Process stopped. Use

Step or Run to continue.

我看不明白这条错误信息,

请指教。
(我已倾囊而出)
 
调用的参数不正确,请把SOURCE贴上来
 
请把代码贴出来.
 
unit thread;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, Grids, DBGrids;
type
Ppath=^Tpath;
Tpath=record
path:string;
end;
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DBGrid2: TDBGrid;
MainMenu1: TMainMenu;
File1: TMenuItem;
FindFile1: TMenuItem;
procedure FindFile1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
wenjianNO:integer;
implementation
uses thread1;
//datamodule2

{$R *.DFM}

function FindFile(path:pointer):Longint;stdcall;
var
SearchRec: TSearchRec;
path1:pointer;
err:integer;
begin
try
err:=FindFirst(Ppath(path)^.path+'*.*',faAnyFile, SearchRec);
while err = 0do
begin
if SearchRec.Name[1]<>'.' then
begin
if ((SearchRec.Attr and fadirectory)>0) AND (SearchRec.Name[1]<>'.') then
begin
datamodule2.table1.Append;
datamodule2.table1.FieldByName('文件编号').asinteger:=wenjianNO;
datamodule2.table1.FieldByName('文件名称').asstring:=searchrec.Name;
datamodule2.table1.FieldByName('文件类型').asstring:='文件夹';
datamodule2.table1.Post;
wenjianNO:=wenjianNO+1;
try
path1:=Pointer(new(Ppath));
Ppath(path1)^.path:=Ppath(path)^.path+String(SearchRec.Name)+'/';
FindFile(path1);
except
exit;
end;
end
else
begin
datamodule2.table1.Append;
datamodule2.table1.FieldByName('文件编号').asinteger:=wenjianNO;
datamodule2.table1.FieldByName('文件名称').asstring:=searchrec.Name;
datamodule2.table1.FieldByName('文件类型').asstring:=ExtractFileExt(SearchRec.Name);
datamodule2.table1.FieldByName('所属文件夹').asstring:=Ppath(path)^.path;
datamodule2.table1.Post;
wenjianNO:=wenjianNO+1;
end;
end;
err:= FindNext(SearchRec);
end;
finally
FindClose(SearchRec);
end;
end;

procedure TForm1.FindFile1Click(Sender: TObject);
var
hThread:THandle;
ThreadID:DWord;
path:pointer;
begin
path:=Pointer(new(Ppath));
Ppath(path)^.path:='h:/';
Hthread:=CreateThread(nil,0,@FindFile,path,0,ThreadID);
if hthread=0 then
messageBox(Handle,'no Thread',nil,MB_OK);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
wenjianNO:=1;
end;

end.
 
unit threadguangpan;


interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, DBGrids;


type
Ppath=^Tpath;

Tpath=record
path:string;

end;

TForm1 = class(TForm)
DBGrid1: TDBGrid;

Button1: TButton;

procedure Button1Click(Sender: TObject);

procedure FormCreate(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;


var
Form1: TForm1;

wenjianNO:integer;

// Sect1:TRTLCriticalSection;


implementation

uses threadmodule;


{$R *.DFM}

function FindFile(path:pointer):Longint;stdcall;

var
SearchRec: TSearchRec;

path1:pointer;

err:integer;

begin

// EnterCriticalSection(Sect1);

try
err:=FindFirst(Ppath(path)^.path+'*.*',faAnyFile, SearchRec);

while err = 0do

begin

if SearchRec.Name[1]<>'.' then
begin

if ((SearchRec.Attr and fadirectory)>0) AND (SearchRec.Name[1]<>'.') then

begin

datamodule2.table1.Append;

datamodule2.table1.FieldByName('文件编号').asinteger:=wenjianNO;

datamodule2.table1.FieldByName('文件名称').asstring:=searchrec.Name;
datamodule2.table1.FieldByName('文件类型').asstring:='文件夹';

datamodule2.table1.Post;

wenjianNO:=wenjianNO+1;

try
path1:=Pointer(new(Ppath));

Ppath(path1)^.path:=Ppath(path)^.path+String(SearchRec.Name)+'/';

// LeaveCriticalSection(Sect1);

FindFile(path1);

except
exit;

end;

end
else

begin

datamodule2.table1.Append;

datamodule2.table1.FieldByName('文件编号').asinteger:=wenjianNO;

datamodule2.table1.FieldByName('文件名称').asstring:=searchrec.Name;
datamodule2.table1.FieldByName('文件类型').asstring:=ExtractFileExt(S
datamodule2.table1.FieldByName('所属文件夹').asstring:=Ppath(path)^.p
datamodule2.table1.Post;

wenjianNO:=wenjianNO+1;

end;

end;

err:= FindNext(SearchRec);

end;

finally
FindClose(SearchRec);

// LeaveCriticalSection(Sect1);

end;

end;


procedure TForm1.Button1Click(Sender: TObject);

var
hThread:THandle;

ThreadID:DWord;

path:pointer;

begin

path:=Pointer(new(Ppath));

Ppath(path)^.path:='h:/';

Hthread:=CreateThread(nil,0,@FindFile,path,0,ThreadID);

if hthread=0 then
messageBox(Handle,'no Thread',nil,MB_OK);

end;


procedure TForm1.FormCreate(Sender: TObject);

begin

//InitializeCriticalSection(Sect1);

wenjianNO:=1;

end;


end.


会发生许多种错误,

最经常发生的是key violation,但我想不通怎么会发生这种错误。

还会出现的错误有:

内存不足;


Project Project1.exe raised edception class EAccessViolatio with
message 'Access violation at address 4CEOOC5B in module
'IDPDX32.DLL'.Read of address FFFFFFFF'.Process stopped. Use
Step or Run to continue.

'access violation at address 00401EE3 in module
'threadProject1.exe' Write of address 018282AC';


更有甚者,运行后连主窗体都看不见,
而且database desktop 无法启动。

大多数重启后,第一次运行此程序都是正常且正确的,但也有不行的时候。

以后几次是肯定不行了。

这个问题已困扰我好长时间了,

请各位打下一定要帮帮忙。



 
换一下内存条,是否还有这个问题?
 
我想大概跟线程的安全性有关吧,

我试用了一下synchronize函数,
结果问题解决了,
虽然还是有不符合我本意的地方,
但那只是小问题。
 

Similar threads

I
回复
0
查看
818
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
720
import
I
顶部