Good Point.

Actually I have developed a threadsafe socket logger. Its pretty cool
actually. You have an logger application running in your system tray and all
you need to do is link in the client / helper units to your code and call

LogMessage(text)

Or

LogMessage(Category, Text) the category will output onto a separate tab
within the socket logger.

I couldn't do without this tool for Delphi developing. It saves stuffing
around with controls or text files, and is fully thread safe. I've used it
on a number of commercial contracts and its been adopted as a usuful in
house tool.

If anyone is interested, I can forward through the code.

Cheers,

Matt.

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Conor Boyd
Sent: Thursday, 17 May 2007 9:54 a.m.
To: NZ Borland Developers Group - Delphi List
Subject: RE: [DUG] Best way to make this thread safe

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


_______________________________________________
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