Thanks for your comprehensive reply. My example was deliberately simplified. I need to see the debug messages in real time and don't want to log them to a file.. I already use a TMemo to log debug messages from the main thread and it is plenty fast enough. My problem or my question is really "how can I log messages from another thread to a memo using critical sections?"
Ross
Main Topics
Browse All Topics





by: Geert_GruwezPosted on 2009-09-06 at 23:18:02ID: 25273004
your main problem is you use a TMemo --> this is a TStringlist --> this is slow
this is overhead !
next to that, you are using a form as well and wanting it to be called MyMainForm
you should use a file to log messages
the one thing you can allways rely on : there is allways a file system.
the best thing is to log messages to a file and
if you want to see the log messages, only then open the file in a TMemo
(possibly add a refresh to reload the file)
with the unit in snippet you have 1 procedure to add text to a log from anywhere
AddLog('This a message from Thread 1', True, 'thread1');
You can change the 'thread1' to anything specific like 'debug'
this way you can separate different message logs
the log files are created with a start timestamp
when they go over a certain size (default 1024Kb) , a new file is started
when files are over 30 days and over 1024Kb they are also cleaned up
default in .exe directory
Select allOpen in new window