Board index » delphi » !Help needed dynamically creating visual components

!Help needed dynamically creating visual components

Help!

I am writing a graphic-based application that allows the user to
dynamically create map points (a simple visual component called TMapPoint,
similar TShape).  I have tried using an array, however the maximum number
of instances (supposedly: 65520 div sizeof(TMapPoint)) causes a compiler
error because the data segment is too large.  I could try to ascertain the
maximum using guesswork, but I want the application to work on a variety of
PC's with varying specifications.

I am attempting to use a list & pointer, in order to maximise memory
efficiency, but this is where I am running into difficulties.  The required
variables are set up thus:

    pMapPoint: ^TMapPoint;
    lstMapPoint: TList;

I can create a new TMapPoint (I think) using the following:

  New(pMapPoint);
  lstMapPoint.Add(pMapPoint);

However the component does not make itself visible and if I try changing
any of the properties (for instance: pMapPoint^.Left := X;), I get a GPF.
Can anybody help me with this problem?

Thanks in advance for any advice you can give me.

________________________________________
Richard Sutcliffe
B.Sc. (Hons) Computing Yr.4

Mail: rsutcli...@enterprise.net
Web: http://homepages.enterprise.net/rsutcliffe/dolphin

 

Re:!Help needed dynamically creating visual components


Quote
Rick wrote:
> variables are set up thus:

>     pMapPoint: ^TMapPoint;
>     lstMapPoint: TList;

> I can create a new TMapPoint (I think) using the following:

>   New(pMapPoint);
>   lstMapPoint.Add(pMapPoint);

> However the component does not make itself visible and if I try changing
> any of the properties (for instance: pMapPoint^.Left := X;), I get a GPF.
> Can anybody help me with this problem?

What the new creates is a dataarea to hold the mappoint object, but the
mappoint hasn't been created yet. The constructor isn't called.

Try the following:

lstMapPoint.Add(MapPoint.Create(self));

or

M := TMapPoint.Create(Self);
M.Parent := DaDrawForm;
lstMapPoint.Add(m);

Remember to call the destructor in the formclose, because
lstmappoint.free merely destroys the pointerarray and not the associated
memoryareas.

For access use TMapPoint(lstmappoint[mapnumber]).X := 0;

Jouke de Boer (Bo...@edte.utwente.nl).

Other Threads