[Lazarus] Lazarus and Application.ProcessMessages

JuuS JuuS at mykolab.ch
Sat Dec 6 16:02:40 CET 2014


Hi all,

A bit late with this and haven't read everything through and through but...

I worked with Delphi for some time and, yes, Application.Processmessages
brings system to knees and processor to 100%.

But in Delphi there was also an Application.Handlemessage...used like this:

    repeat
      Application.HandleMessage;
    until AKeyPressed (or whatever);

...and the system is calm (normal load) and the program responsive. It
was like Handlemessage was sipping water drops dripping from a fern
leaf, while Processmessages was drinking from a fire hose... :)

I don't know if anyone else has mentioned this, not reading all the
mails, and also don't know if Handlemessage is implemented in Lazarus
(not being by my computer right now).

Hope this helps someone.

Julius

On 05/12/2014 14:59, Lukasz Sokol wrote:
> On 04/12/14 20:34, waldo kitty wrote:
>> On 12/4/2014 10:24 AM, Lukasz Sokol wrote:
>>> (OnTimer execution has the same problem : inevitably splits the procedure into
>>> more procedures, that can no longer use same local variables and stuff)
>>
>> you can't make them subroutines of the subroutine?
>>
> 
> Interesting, but breaks the flow of human reading (as, comparably, top posting does):
> because subroutines have to be defined at the top of the subroutine...
> 
>> eg:
>>
>> program foobie;
>>
>> procedure dofoobie;
>>
>> var
>>   thisfoo : integer = 0;
>>   thatfoo : integer = 0;
>>
>>   procedure littlefoobie; ///  << this logically comes AFTER but we don't know that until we read...
>>   begin
>>     inc(thisfoo,thatfoo);
>>     inc(thatfoo);         /// this probably is not much of a problem when a subroutine is this short
>                             // it's the much-longer ones 
>>   end;
>>
>> begin
>>   repeat
>>     begin
> 	foobiee( ... ); /// ... that this logically comes first
>>       littlefoobie;
>>       writeln(thisfoo,'    ',thatfoo);
>>     end;
>>   until thisfoo >= 25;
>> end;
>>
>> begin
>>   dofoobie;
>> end.
>>
>>
> 
> How would you put this into subroutines:
> 
> 
> procedure very_long_initialization_routine;
> // (var some_big_list_of_variables... )
> 
> begin
>   Timer1.Enabled := false;
>  
>   do_this();
>   do_that();  // now for the sake of argument, say this routine fires up a thread reading in 10000s of file names through FindFirst/FindNext
>   // now we need a long delay before calling do_foo() that would operate on that list, so
>  
>   Timer1.OnTimer := do_the_rest_of_initialization();
>   Timer1.Delay   := 10000; // pseudo-code, can't remember how was that exactly called
>   Timer1.Enabled := true;
>   // that's it, we need to split here to give message loop opportunity to do Application.ProcessMessages
> end;
> 
> /// (and here we break variable locality...)
> 
> procedure do_the_rest_of_initialization;
> begin
>   do_foo(...);
>   // rinse&repeat if you have more sections like that doing different things...
> end;
> 
> One can of course have TTimer as locally created object in the very_long_initialization_routine, yes... but an
> Application.ProcessMessages + sleep(100) loop is probably much easier to type (and debug, and read).
> 
> Not mentioning that probably loop would be a wee little (tiny) bit more precise than calling the Timer ?
> 
> (that of course YMMV and IMvhO)
> 
> el_es
> 
> 
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
> 




More information about the Lazarus mailing list