On Mon, 27 Mar 2023 14:40:26 +0200
Luca Olivetti via lazarus <lazarus@lists.lazarus-ide.org> wrote:

> 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.

What does TExecInThread.Execute do?

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



Mattias

-- 
_______________________________________________
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus

Reply via email to