Yup, that should do the trick in this case.

The following isn't really answering your question, and obviously it
depends on the circumstances, but for logging for a developer's benefit,
I just use the OutputDebugString function in the Windows unit, and then
use DbgView from SysInternals to log the output from my apps that way.
Don't have to worry about threading/logging issues then.  Maybe that's
some help to somebody.

Cheers,

C.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Alister Christie

If you're wanting to manipulate the VCL you need to call
synchronize(aMethod), which will sync your thread to the main
application thread - the VCL is not thread-safe.  In aMethod you could
do your writelog.  But I'm also not much of a threading expert so
someone else may have a better method.

Nick wrote:
> I got a function here I use for logging to a richedit on my main form 
> (this is just in functions unit)
>
> Procedure WriteLog(sString : string; opt : LogOption); Begin  With 
> frmMain.reLog do
>    begin
>      If lines.Count > 200 then lines.Delete(0);
>
>      lines.add(sString);
>      SelStart := length(text) - (length(sString)+2);
>      SelLength := length(sString);
>      Case LogOption(opt) of
>        loStart   : begin SelAttributes.Style := [fsbold]; 
> SelAttributes.Color := clBlue;   end;
>        loNormal  : begin SelAttributes.Style := [];       
> SelAttributes.Color := clBlack;  end;
>        loError   : begin SelAttributes.Style := [fsbold]; 
> SelAttributes.Color := clRed;    end;
>        loFinished: begin SelAttributes.Style := [fsbold]; 
> SelAttributes.Color := clBlue; lines.add('');  end;
>      End;
>      SelStart := Length(Text);
>      Perform(EM_SCROLLCARET, 0, 0);
>    end;
> End;
>
> Now I want to use that function in my threads to log things. However 
> if I call it just like this  WriteLog('Failed to connect! DB Error', 
> loError); I could run into access violations But not quite sure the 
> best way to do this to make it thread safe and use as little extra 
> code as possible..
>
> Should I create my own function like this  WriteLogThread('Failed to 
> connect! DB Error', loError); in my TThread and then in that procedure

> just do criticalsection start  WriteLog(message, st);  //this calls 
> the function in my general functions unit criticalsection end or could

> I just use critical sections in my functions unit around the 
> procedure.

_______________________________________________
NZ Borland Developers Group - Delphi mailing list
Post: delphi@delphi.org.nz
Admin: http://delphi.org.nz/mailman/listinfo/delphi
Unsubscribe: send an email to [EMAIL PROTECTED] with Subject: unsubscribe

Reply via email to