Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi7: Instancing controls (control-array) at runtime? plz help

48 views
Skip to first unread message

Mike Winauer

unread,
May 3, 2004, 3:28:14 PM5/3/04
to
Hi Newsgroup,

I'm using Delphi 7 Enterprise, and got following Problem:

I have a TabStrip(TPageControl), with 8 Pages(TTabSheet), that show
different stuff, but on top of every of those 8 TabSheets i need an
instance of a Frame (which contains 2 TextBoxes, 2 Labels, and an icon).

Now, i know i could drag'n'drop that frame on every TabSheet at
DesignTime, but i would like to do it at Runtime.

The Catch is, i need the contents of these 8 Instances of that Frame
(i.e. the texts of those 2 textboxes) synchronised, meaning, when i
enter a text in the textbox on TabSheet1, all other 7 TabSheet's
Frames should show the same text. That goes easier, if i can recurse
thru a List, rather run the same code 8 times one after another,
PLUS i dont know yet, if i wont have more than 8 pages some time)


The Frame i wanna instantiate, looks pretty much like this:
(frmProduktName.pas)

type
TProduktName = class(TFrame)
lblName: TLabel;
lblDescription: TLabel;
txtName: TEdit;
txtDescription: TEdit;
// plus some cosmetic controls (Bevel, Groupbox...)
private
{ Private declarations }
public
{ Public declarations }
end;


My approach was, building up a list at runtime, where every item
contains an instance of that frame, and a pointer to the next one:
(frmMain.Pas)

Type
pProdName = ^TProdName;

TProdName = record
frmForm : TProduktName; // <-- see above
Next : pProdName;
end;


that's how i tried to build up the list:

procedure CreateFrames();
var
pCurPName : pProdName;
tmpPName : TProduktName;

begin

// Create Instance of the Frame into TabSheet1
tmpPName := TProduktName.Create(frmMain.TabSheet1);
tmpPName.Align := alTop;

// Create ListEntry, Patch Frame into it
New(pCurPName);
pCurPName.Next := nil;
pCurPName.frmForm := tmpPName;

pFirstPName := pCurPName;

// then create the other 7 elements samy way and add em
// to the list, one by one
end;


Now, here's the thing: the Instance of the Frame creates just fine, the
browsing thru the instances worx too, they just won't show up in the
TabSheet. I can set/get the values of all it's properties (Height,
Top, Align, ...), but even tho Visible is true, it wont show, no matter
who's Repaint-Method i fire up (TForm, TTabSheet, TPageControl...)

It's pretty obvious i did this with the book on my lap, and i probably
just asked the most stupid question in the world, but this is my first
delphi project, and my last experience with pointers and lists goes
back to the good old Borland Pascal 7.0 times, so any help will be
greatly appreciated.

Or does anyone know another way to create a number of instances
of an object, or control-arrays in general?
(in VB it was so easy, create n controls of same type, give em same
name, ascending indexes and u got the control-array)


Thanx a lot in advance,

Mike Winauer

Bruce Roberts

unread,
May 3, 2004, 4:10:05 PM5/3/04
to

"Mike Winauer" <MW...@gmx.at> wrote in message
news:301b4460.04050...@posting.google.com...

> Or does anyone know another way to create a number of instances
> of an object, or control-arrays in general?
> (in VB it was so easy, create n controls of same type, give em same
> name, ascending indexes and u got the control-array)

Instead of creating a list you could simply populate an array with the
controls. But I think that you are over complicating things. The most simple
approach would be to place a panel above the page control with the desired
controls. If you really need separate controls on each tab sheet use the tab
sheet's OnShow event to set the control(s) to the correct text.


Tom de Neef

unread,
May 4, 2004, 10:05:02 AM5/4/04
to
"Mike Winauer" <MW...@gmx.at> wrote in message
news:301b4460.04050...@posting.google.com...

What does the book say about owner and parent? Check help. Without a parent
the control will not know when to show even with visible=true.
Tom

0 new messages