Board index » delphi » visual components dynamically created

visual components dynamically created

Hello,

I've tried to dynamically create visual components in about this way:

function....
var
   dyn:^Tshape;
begin
        new(dyn);
        dyn^:=create(Tshape);
        XXXXXX
end;

where the XXXXXX represents everything linked to the Tshape component
(methods or properties). It doesn't work with either with button,
labels,...

Why?

Thank you for answering,

                                        Sacha

--
Sacha Labourey          Ecole Polytechnique federale de Lausanne
4 Ministraux 32         diwww.epfl.ch/~slaboure
2000 Neuchatel/CH       +41 38 25 55 13

 

Re:visual components dynamically created


Quote
Sacha Labourey wrote:

> Hello,

> I've tried to dynamically create visual components in about this way:

> function....
> var
>    dyn:^Tshape;
> begin
>         new(dyn);
>         dyn^:=create(Tshape);
>         XXXXXX
> end;

> where the XXXXXX represents everything linked to the Tshape component
> (methods or properties). It doesn't work with either with button,
> labels,...

> Why?

> Thank you for answering,

>                                         Sacha

> --
> Sacha Labourey          Ecole Polytechnique federale de Lausanne
> 4 Ministraux 32         diwww.epfl.ch/~slaboure
> 2000 Neuchatel/CH       +41 38 25 55 13

Component identifiers in delphi are actually pointers to the component,
so you don't need to do declare an explicit pointer to your TShape.
You also need to specify the component's parent via its parent property.

e.g

var
   dyn:TShape;
begin
   dyn:=TShape.Create(Self);
   dyn.Parent:=Self;
   XXXXXX
end;

Stefano Busti

Re:visual components dynamically created


In article <32779238.7...@studi.epfl.ch>
           Sacha.Labou...@studi.epfl.ch "Sacha Labourey" writes:

Quote
> Hello,

> I've tried to dynamically create visual components in about this way:

> function....
> var
>    dyn:^Tshape;
> begin
>         new(dyn);
>         dyn^:=create(Tshape);

dyn is a pointer, so you don't want to try to dereference it, at least
not before you have created the instance that you want to point to so

dyn := TShape.Create;

Should work.

Quote
>         XXXXXX

and XXXXX might have to be cast ie,

   TShape(dyn)^.free;

Quote
> end;

> where the XXXXXX represents everything linked to the Tshape component
> (methods or properties). It doesn't work with either with button,
> labels,...

> Why?

Did I tell you I was guessing?

--
suck The Goat

Re:visual components dynamically created


Quote
In article <32779238.7...@studi.epfl.ch> Sacha Labourey <Sacha.Labou...@studi.epfl.ch> writes:
>Date: Wed, 30 Oct 1996 18:36:56 +0100
>From: Sacha Labourey <Sacha.Labou...@studi.epfl.ch>
>Subject: visual components dynamically created
>Hello,
>I've tried to dynamically create visual components in about this way:
>function....
>var
>   dyn:^Tshape;
>begin
>        new(dyn);
>        dyn^:=create(Tshape);
>        XXXXXX
>end;

hello,

the Delphi object model IMPLICITELY creates objects dynamically on the
heap.
   var dyn : tShape
is already a pointer to an object type,
   dyn := tShape.create(...)
allocates an object on the heap,
   dyn.amethod
is being implicitely dereferenced.
Somewhere on www.borland.com you find
documents which discuss the new object
model in detail (Sorry, I have forgotten the exact
location, mail me if you are interested, I have
the text flying around somewhere)

hope that helps, Volker

Other Threads