Delphi .NET (2) Database (71) Delphi IDE (89) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
Threads and the VCL in DLLs (Delphi 6)
This article has not been rated yet. After reading, feel free to leave comments and rate it.
Question:
I have a DLL that creates a form, which spawns a thread to do processing. I am unable to get either Synchronize or OnTerminate to function properly in the secondary thread. In both cases, the thread appears to be waiting for idle time in the main application thread indefinitely. I started the project in Delphi 5, and wasn't having any problems.
Below is an simplified version of my code.
Answer:
There are two possible scenarios:
- Your main application is a Delphi application.
Build both the main application and your DLL with the VCL package
- Your main application is NOT a Delphi application.
Assign Classes.WakeMainThread and call CheckSynchronize from the method you assigned. You must make sure that CheckSynchronize is called from the main (VCL) thread yourself.
 | |  | | type
TTestThread = class(TThread)
protected
procedure Execute; override;
public
procedure Test;
end;
procedure TTestThread.Test;
begin
Form1.Edit1.Text := DateTimeToStr(Now);
end;
procedure TTestThread.Execute;
begin
FreeOnTerminate := true;
Synchronize(Test);
end;
prcedure Form1.Button1Click(Sender: TObject);
begin
TTestThread.Create(False);
end;
function LoadForm: THandle;
begin
Form1:= TForm1.Create(nil);
with Form1 do
begin
Show;
Result := Handle;
end;
end;
| |  | |  | You don't like the formatting? Check out SourceCoder then!
Comments:
|