[Lazarus] animated splash screen for lengthy operation, works with windows, doesn't with linux

Luca Olivetti luca at wetron.es
Mon Mar 27 14:40:26 CEST 2023


El 27/3/23 a les 11:59, Luca Olivetti via lazarus ha escrit:

> [*] instead of opening the query I spawn a thread that opens it, wait 
> for it to finish while executing Application.ProcessMessages and 
> eventually reraise the exception that was generated inside the thread.


Speaking of which, I encapsulated it in a procedure (TWaitForm is the 
spash screen, Aproc is a procedure of object, TExecInThread simply calls 
AProc in its execute method):

procedure ExecWithSplash(AProc:TThreadProc);
var wf:TWaitForm;
     ut:TExecInThread;
begin
   Wf:=TWaitForm.Create(Application);
   WF.Show;
   ut:=TExecInThread.create(AProc);
   while not ut.Finished
     Application.ProcessMessages
   wf.free;
   if ut.FatalException<>nil then
     raise(ut.FatalException);
   ut.free;
end;


The problem here is, if AProc raises an exception, I cannot free the 
thread causing a leak.
Since I don't want to expose the thread to the caller, so that it can 
free it in its exception handler, how can I copy FatalException so I can 
free the thread and only then raise the exception?
I cannot simply assign it to a local variable since the TThread 
destructor also frees FatalException.

Encapsulating it in a try..finally block also doesn't work

try
   if ut.FatalException<>nil then
     raise(ut.FatalException);
finally
   ut.free;
end

Bye
-- 
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010)  Fax +34 93 5883007



More information about the lazarus mailing list