Y
ybbqy
Unregistered / Unconfirmed
GUEST, unregistred user!
这两天写一个程序,一运行即出现access violation at address写了一个简单版的测试程序 ,错误被重现。如果去掉ttt函数中的finally与except则不会有出现错误,为什么会这样?DLL程序 /////////////////////////////////////////////////////////////////////////////unit UnitDll;interfaceuses Classes;implementationfunction ttt: integer;stdcall;
var lines:TStrings;
begin
{ 这样即没问题 try try lines:=TStringList.Create;
lines.Free;
finally end;
except end;
} try try lines:=TStringList.Create;
lines.Free;
finally end;
except end;
end;
exports ttt;
end.
调用程序////////////////////////////////////////////////////////////unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type TForm1 = class(TForm) procedure FormCreate(Sender: TObject);
private { Private declarations } public { Public declarations } end;
type TMyThread = class(TThread) private { Private declarations } protected procedure Execute;
override;
end;
function ttt(): integer;stdcall;
external 'dll.dll';var Form1: TForm1;
MyThread1:TMyThread;
MyThread2:TMyThread;implementation{$R *.dfm}{ TMyThread }procedure TMyThread.Execute;
begin
inherited;
while truedo
begin
ttt;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyThread1:=TMyThread.Create(false);
MyThread2:=TMyThread.Create(false);
end;
end.
var lines:TStrings;
begin
{ 这样即没问题 try try lines:=TStringList.Create;
lines.Free;
finally end;
except end;
} try try lines:=TStringList.Create;
lines.Free;
finally end;
except end;
end;
exports ttt;
end.
调用程序////////////////////////////////////////////////////////////unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type TForm1 = class(TForm) procedure FormCreate(Sender: TObject);
private { Private declarations } public { Public declarations } end;
type TMyThread = class(TThread) private { Private declarations } protected procedure Execute;
override;
end;
function ttt(): integer;stdcall;
external 'dll.dll';var Form1: TForm1;
MyThread1:TMyThread;
MyThread2:TMyThread;implementation{$R *.dfm}{ TMyThread }procedure TMyThread.Execute;
begin
inherited;
while truedo
begin
ttt;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyThread1:=TMyThread.Create(false);
MyThread2:=TMyThread.Create(false);
end;
end.