El 27/3/23 a les 16:13, Michael Van Canneyt via lazarus ha escrit:
On Mon, 27 Mar 2023, Luca Olivetti via lazarus 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;
Ehm. In case of an exception, ut will never be freed ?
That's what I said.
I was looking for a way to free it *and* raise the exception in the
context of the main thread.
If I move the ut.free before the raise, the exception has already been
freed and it's invalid, causing a sigsev, if I enclose it in a
try..finally the exception handler will be called after the finally has
freed the thread (and the exception, so it's the same problem).
Bye
--
Luca Olivetti
Wetron Automation Technology http://www.wetron.es/
Tel. +34 93 5883004 (Ext.3010) Fax +34 93 5883007
--
_______________________________________________
lazarus mailing list
lazarus@lists.lazarus-ide.org
https://lists.lazarus-ide.org/listinfo/lazarus