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.

I hope that makes sense =)
Thanks guys.
_______________________________________________
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