DelphiFAQ Home Search:

Threads and the VCL in DLLs (Delphi 6)

 

commentsThis 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:


  1. Your main application is a Delphi application.
    Build both the main application and your DLL with the VCL package

  2. 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;
You don't like the formatting? Check out SourceCoder then!
Content-type: text/html

Comments:

2012-06-05, 21:36:04
anonymous from China  
<strong> http://www.coachout..strong> <a href=' http://www.coachout..g>Coach Outlet Online</strong></a><br />
<strong> http://www.coachfac..strong> <a href=' http://www.coachfac..g>Coach Factory</strong></a><br />
<strong> http://www.myloveco..strong> <a href=' http://www.myloveco..g>Coach Outlet Online</strong></a><br />
<strong> http://www.buyincoa..strong> <a href=' http://www.buyincoa..g>Coach Outlet</strong></a><br />
<strong> http://www.cheapcoa..strong> <a href=' http://www.cheapcoa..g>Cheap Coach Handbags</strong></a><br />
<strong> http://www.coachfac..strong> <a href=' http://www.coachfac..g>Coach Factory Outlet</strong></a><br />
<strong> http://www.buycoach..strong> <a href=' http://www.buycoach..g>Coach Outlet Online</strong></a><br />
<strong>www.coachoutletonfactory.net</strong> <a href=' http://www.coachout..g>Coach Factory Outlet</strong></a><br />
<strong>www.coachoutletonline4you.us</strong> <a href=' http://www.coachout..g>Coach Outlet Online</strong></a><br />
<strong>coachfactoryoutletq.net</strong> <a href=' http://www.coachfac..g>Coach Factory</strong></a><br />
<strong>gotocoachoutlets.net</strong> <a href=' http://www.gotocoac..g>Coach Outlet Online</strong></a><br />
2012-11-12, 02:17:12
anonymous from United Kingdom  
2013-01-24, 23:44:27
anonymous from China  

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: