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

Michael Van Canneyt michael at freepascal.org
Tue Mar 28 00:01:57 CEST 2023



On Mon, 27 Mar 2023, Luca Olivetti via lazarus wrote:

> El 27/3/23 a les 17:26, Luca Olivetti via lazarus ha escrit:
>> El 27/3/23 a les 16:50, Michael Van Canneyt ha escrit:
>> 
>>>>>
>>>>> 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).
>>>
>>> Normally, I'd do
>>>
>>> Raise 
>>> Exception(ut.fatalexception.classtype).Create(ut.fatalexception.message);
>> 
>> Actually I'd have to first create the exception, then free ut, then 
>> raise the exception (keep in mind that FatalException is a TObject and 
>> it isn't necessarily of class Exception), otherwise a direct raise as 
>> you wrote would not free ut.

I only gave the line to show that you can raise a second exception object
with the same class and message as the original.

>>
>>    MyException:=nil;
>>    if ut.FatalException<>nil then
>>    begin
>>       if ut.FatalException is Exception then
>> 
>> 
> MyException:=Exception(ut.FatalException).Create(Exception(ut.FatalException).message)
>
> Ouch, I left out the ClassType, but if I change it to
>
> 
> MyException:=Exception(Exception(ut.FatalException).ClassType).Create(Exception(ut.FatalException).message)
>
> it's an instant segfault.

My bad, I made a typo, it should have been

MyException:=ExceptionClass(ut.FatalException).ClassType).Create(Exception(ut.FatalException).message)

with 
ExceptionClass= class of exception;

Actually, I never write it like this in one statement, I save the class pointer and message
in local variables, do cleanup first and then use the class pointer and
message later to raise an exception. But the effect is the same: you create
a copy with the same class and message as the original.

Michael.


More information about the lazarus mailing list