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.
// THREAD
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;
// FORM
prcedure Form1.Button1Click(Sender: TObject);
begin
TTestThread.Create(False);
end;
// DLL function
function LoadForm: THandle;
begin
Form1:= TForm1.Create(nil);
with Form1 do
begin
Show;
Result := Handle;
end;
end;