Board index » delphi » Dynamically created object crashes when calling inherited Create

Dynamically created object crashes when calling inherited Create

Hello!

I wonder if somebody could help me!

I have a class TProcessDescription -
which inhterits from TObject.

I have declared a Pointertype
type PProcess = ^TProcessDescription;

In my program I try to create this object dynamically
and call its create method

procedure myForm.myProc;
var
   proc_desc : PProcess;
begin
  new(proc_desc);        // OK
  proc_desc^.create;   // Wooooouups
  // The create method crashes when calling
  // inherited create;
end;

Why... WhYY WHYYYYY!

Terje
Floroe, Norway

 

Re:Dynamically created object crashes when calling inherited Create


Found it out myself!

procedure myForm.myProc;
var
   proc_desc : PProcess;
begin
  new(proc_desc);
  // proc_desc^.create;   // ERROR
  proc_desc^ := TProcessDescription.create; // OK

end;

Terje

Re:Dynamically created object crashes when calling inherited Create


On Thu, 14 Jan 1999 09:22:33 +0100, "Terje Viken"

Quote
<terje.vi...@eunet.no> wrote:
>Hello!

>I wonder if somebody could help me!

>I have a class TProcessDescription -
>which inhterits from TObject.

>I have declared a Pointertype
>type PProcess = ^TProcessDescription;

>In my program I try to create this object dynamically
>and call its create method

>procedure myForm.myProc;
>var
>   proc_desc : PProcess;
>begin
>  new(proc_desc);        // OK
>  proc_desc^.create;   // Wooooouups
>  // The create method crashes when calling
>  // inherited create;
>end;

>Why... WhYY WHYYYYY!

Hi Terje,

  I dont think the New procedure could be used to actually create an
object, with its virtual table and methods. It basically just reserves
a block of memory and returns a pointer to it.
 Usually you would call the constructor of an object this way :
proc_desc := TProcessDescription.Create;
<
Hope this helps.
If not then i am the one who is gonna learn something here ;-)

Regards
Robert

Other Threads