[fpc-pascal] methods of an object to create others objects

Marcos Douglas md at delfire.net
Tue Jul 6 19:51:30 CEST 2010


On Tue, Jul 6, 2010 at 1:39 PM, Marco van de Voort <marcov at stack.nl> wrote:
> In our previous episode, Andrew Brunner said:
>> > obj1 := nil;
>> > obj2 := nil;
>> > Try
>> > ?obj1 := TMyObject.Create;
>> > ?obj2 := TMyObject.Create;
>> >
>> > ?obj1.DoSomething1;
>> > ?obj2.DoSomething2;
>> > finally
>> > ?obj1.Free;
>> > ?obj2.Free;
>> > end;
>> >
>> > The objectcs are protected. But is boring... :)
>> > Everybody codify like that, afraid if resources are not available?
>> >
>>
>> Nope. If Obj2 failed to create you will have a problem with Obj2.Free.
>
> Nope. That's why it is free and not destroy.

Okay Marco, you explained to Andrew!  ;-)


>> But taking the real issue to the next
>> level... What if something in Obj1.free raised an exception... Then
>> you will not free Object2.  The "best" way is with nested exception
>> handling.  Sorry :-)
>
> That's the problematic one I think.

Can an exception happen in Free method?!  :-O


Marcos Douglas



More information about the fpc-pascal mailing list