Re: How to allocate new class instance on the heap?




<chrisspencer02@xxxxxxxxx> wrote in message
news:1117053341.586509.227480@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

> var
> MyRec : PMyRec;
> begin
> New(MyRec);
> // Do stuff with MyRec
> Dispose(MyRec);
> end;

For additional safety use

New (MyRec);
try
// do stuff with MyRec
finally
Dispose (MyRec);
end;

> Should I use the same method for _class_ instances (with constructors
> and destructors) as I describe for records above? Or is there another
> preferred method?

Absolutely not. Its not a question of being preferred, its a matter of
working correctly. The general form of creating class instances is

ClassInstanceVariable := tClassName.Create { ( <constructor
parameters>) };


.