Board index » delphi » Creating Forms, Destroying Forms

Creating Forms, Destroying Forms

I've got a question regarding how Delphi creates and destroys forms.

I've got a class derived from TForm. It's not created automatically in
the project source (I commented out the CreateForm call).

So I have a procedure,

procedure Foo;
var
        aForm: TMyForm;
begin
        aForm := TMyForm.Create(self);

        ...

        aForm.Destroy;
end;

Create is my constructor that looks like,

constructor TMyForm.Create(Owner: TComponent);
begin
        inherited Create(Owner);

        ...
end;

I guess what I'm looking for is the specifics of what Delphi will do in
procedure "foo".

I've created a local/automatic variable in the procedure of type
TMyObject.

Is the memory allocated automatically?

Does the call to Create just initialize the function, or is the memory
allocated as well?

If I did,

var
        anObject: ^TMyObject;

Would I then have to make a call to GetMem??

I'd really like to see a book that focuses on Object Oriented Pascal as
it relates to Delphi, rather than just another discussion of creating
forms, how to set up OnClick events, and other stuff that has been
covered 500 times before...

Any suggestions or info would be appreciated... as would other questions
or experience with this topic.

Thanks,
David.

 

Re:Creating Forms, Destroying Forms


On Wed, 10 Sep 1997 11:55:27 -0700,
David Griffiths <davidgriffi...@iname.com> said:

Quote
> procedure Foo;
> var
>    aForm: TMyForm;
> begin
>    aForm := TMyForm.Create(self);

>    ...

>    aForm.Destroy;
> end;
> I guess what I'm looking for is the specifics of what Delphi will do in
> procedure "foo".

Eh, uh... it will create your form for you...
Sorry, I don't really understand the question.

Quote
> I've created a local/automatic variable in the procedure of type
> TMyObject.

> Is the memory allocated automatically?

AFAIK, yes.

Quote
> Does the call to Create just initialize the function, or is the memory
> allocated as well?

Does it "initialize" _which_ function? Create? Well, calling Create
will _execute_ Create, not just "initialize" it, I would think.

I think the Create method of the Form object allocates memory.

Quote
> If I did,

> var
>    anObject: ^TMyObject;

> Would I then have to make a call to GetMem??

No, "anObject := TMyObject.Create;" allocates the memory. Remember to
call the Free method to dispose of your object, and set anObject := nil,
when you're done with it. And one more thing: drop the "^" -- objects in
Delphi _are_ pointers, so you'd get a pointer-to-a-pointer your way.

Quote
> I'd really like to see a book that focuses on Object Oriented Pascal as
> it relates to Delphi, rather than just another discussion of creating
> forms, how to set up OnClick events, and other stuff that has been
> covered 500 times before...

Delphi 2 Unleashed, Charlie Calvert. Borland Press/Sams Publishing 1996;
ISBN 0-672-30858-4; Library of Congress Catalog Card Number 95-72336.

--
Christian R. Conrad

----------------------------------------------------------------------
Proud and sole owner of all opinions (except quotes) expressed above!

Other Threads