[Lazarus] WriteLn back to the GUI

Lukasz Sokol el.es.cr at gmail.com
Thu Oct 24 11:47:00 CEST 2013

On 23/10/13 20:16, ListMember wrote:
> On 2013-10-23 21:11, Marco van de Voort wrote:
>> On Wed, Oct 23, 2013 at 09:59:04AM +0300, ListMember wrote:
>>> My ultimate goal, after finding where it is declared, is to
>>> locally modify that part of the sources so that (instead of
>>> writing to the console) it will use a global callback to display
>>> whatever WriteLn'ed in a TMemo.
>> There is no source of writeln, it is split up into various calls by
>> the compiler. However in the end those writeln routines write a
>> string, and that routine can be redirected.
>> Have a look at fpc/packages/streamio.pp
>> Running assignstream() on "output" would redirect all normal
>> writeln output to the stream that is the second parameter.
> StreamIO isn't, unfortunately, good enough for me. I need to see
> WriteLn output in real-time, not when the application (or the called
> function) ends.

Aside from other ( better) ideas I've seen in this thread :

why not create a TThread hanging on the output pipe, checking it periodically,
(or maybe hooking it to some signal that maybe is passed when stream is written to?)
NOT interfering with GUI, but then signalling / passing the content
to the main thread in a 'OnWriteln' event manner ? 
You'd have to have this thread copy the output stream to a buffer anyway, and then
passing it to main thread, probably copy it again.

Because if your application is single-threaded (GUI thread only) or have other
 threads around that use writeln(), your OnWriteln 'event' in the
GUI won't happen until the GUI thread is ready to handle it anyway (hits the Idle loop)
(because it only has one context, yes LCL is single threaded) so there is not
 much 'real time' here that you can assume.


More information about the Lazarus mailing list