hi..

usually I'd design components slightly differently. the example below
means the thread has no dependencies on the form (proper encapsulation
etc).. also needs no globals, critical sections, timers, circular
'uses' clauses...

something like this (delphi pseudocode):

TmyStringEvent = procedure(sender:tobject;const aStr:string) of object;

TMyThread = class(TThread)
private
  FUpdateStringSync:string;
  FOnStringEvent:TmyStringEvent;
  procedure UpdateString(const aStr:string);
  procedure UpdateStringSync;
published
  property OnStringEvent:TmyStringEvent read FOnStringEvent write
FOnStringEvent;  
end;

procedure TMyThread.UpdateString(const aStr:string);
begin
 { happens in thread context }
 { call this function eg from the execute override }
 FUpdateStringSync:=aStr;
 Syncronize(UpdateStringSync);
end;

procedure TMyThread.UpdateStringSync;
begin
 { happens in main thread context }
 { do not call this method directly. use UpdateString }
 if assigned(FOnStringEvent) then
 begin
 FOnStringEvent(self,FUpdateStringSync);
 end;
end;

then use this component in you main application like:

TMyForm = class(TForm)
private
  procedure CallbackStringEvent(sender:tobject;const astr:string);
{ other stuff }
end;

{ eg: in TmyForm.create }
aThread:=TMyThread.Create(True);
aThread.OnStringEvent:=self.CallbackStringEvent;
aThread.Resume;

procedure TmyForm.CallbackStringEvent(sender:tobject;const
astr:string);
begin
 Memo1.lines.add(aStr);



__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail
http://personal.mail.yahoo.com/
---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED] 
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to