DELPHI7的一个奇怪问题,关于在多线程中DLL,创建释放。(100)

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.
 
那可以肯定是 lines 的问题了, 会不会是 字符串 string 在 DLL 中要引用 ShareMem 单元?
 
目前没有用到此类技术!了解,学习
 
用临界区保护起来?
 
不知为什么,加了ShareMem 就好用了~分给liuls同志了~
 
顶部