Thanks for all your input.  I have decided that this approach is ending up
very clumsy and its pretty slow to paint.  I have now switched to the TMS
StringGrid control which is doing everything I want and more.

Should have gone with that at the start really!

JohnB

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf
Of Wayne Roser
Sent: 03 July 2007 22:43
To: Borland's Delphi Discussion List
Cc: 'Borland's Delphi Discussion List'
Subject: Re: Component or Frame Arrays

You need to keep some list (and an array is a list) of pointers to the
TFrmFuse objects you are creating or you cannot reference them.
So if we combine your code and some of the examples below


var
  ListOfFuseItems:TList;





procedure TfmFuseConfig.FormShow(Sender: TObject); Var i: Integer; begin
ListOfFuseItems:=TList.Create;
  for i := 0 to 7 do
    ListOfFuseItems.Add(AddFuseItem(i)); //add the pointer to the new
FuseItem
  end;
end;


function TfmFuseConfig.AddFuseItem(pIndex: Integer): TFrmFuse; //return the
pointer to what you create var
  NewFuse : TFrmFuse;
begin
  NewFuse := TFrmFuse.Create(Self);
  with NewFuse do begin
      Parent := Self;
      Visible := True;
      Align := alTop;
      Name := 'FuseNo' + IntToStr(pIndex);
  end;
  result := NewFuse; //this returns the pointer to what you just created
end;


Now you can refer to any of your TFrmFuse objects with (example references
i-th one)
        TFrmFuse(ListOfFuseItems[i])
and 
        TFrmFuse(ListOfFuseItems[i]).ItemName
will refer to the ItemName TPanel on the i-th TFrmFuse



Last time I did this I used the equivalent of NewFuse :=
TFrmFuse.Create(nil); and then freed them all in my own destructor

HTH
Wayne




Borland's Delphi Discussion List <[email protected]> on Monday, 2 July 2007
at 11:32 p.m. +0000
wrote:
>OK Thsnks for your help, I can now add the frames at runtime I am 
>adding them in the formShow event at the moment just for testing.
>
>I still can't access the frame's sub components.  
>As you can see I am setting the subcomponents true.  
>How do I access these properties from my main form?
>
>In my main form show event I load up 8 instances of the frame:
>
>procedure TfmFuseConfig.FormShow(Sender: TObject); Var i: Integer; 
>begin for i := 0 to 7 do
>  AddFuseItem(i);
>end;
>
>procedure TfmFuseConfig.AddFuseItem(pIndex: Integer); begin FuseList := 
>TFrmFuse.Create(Self); with FuseList do
>  begin
>    Parent := Self;
>    Visible := True;
>    Align := alTop;
>    Name := 'FuseNo' + IntToStr(pIndex);
>  end;
>end;
>
>This leaves me with 8 frames visible on my form, I assume with Names of 
>FuseNo0 throught to FuseNo7.
>How do I access these frames and their sub components?  I have tried 
>populating their properties in the AddFuseItem procedure but I just get 
>a syntax error saying undeclared identifier.
>
>E.g.
>
>procedure TfmFuseConfig.AddFuseItem(pIndex: Integer); begin FuseList := 
>TFrmFuse.Create(Self); with FuseList do
>  begin
>    Parent := Self;
>    Visible := True;
>    Align := alTop;
>    Name := 'FuseNo' + IntToStr(pIndex);
>    ItemDesc.Caption := Name;// this line errors......
>  end;
>end;
>
>
>
>This is the source for the frame...........................................
>unit PICFuseItem;
>
>interface
>
>uses
>  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, 
>Forms,
>
>  Dialogs, StdCtrls, ExtCtrls;
>
>type
>  TfrmFuse = class(TFrame)
>    pnlFuseEntry: TPanel;
>    cmbValue: TComboBox;
>    pnlName: TPanel;
>    pnlDescription: TPanel;
>  private
>    { Private declarations }
>  public
>    { Public declarations }
>    Constructor Create(AOwner: TComponent);
>    property ItemName: TPanel Read pnlName Write pnlName;
>    property ItemValues: TComboBox Read cmbValue Write cmbValue;
>    property ItemDesc: TPanel Read pnlDescription Write pnlDescription;
>  end;
>
>implementation
>
>{$R *.dfm}
>Constructor TfrmFuse.Create(AOwner: TComponent); begin
>  inherited;
>  pnlName.SetSubComponent(True);
>  cmbValue.SetSubComponent(True);
>  pnlDescription.SetSubComponent(True);
>end;
>
>end.
>
>-----Original Message-----
>From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On 
>Behalf Of zayin
>Sent: 30 June 2007 02:10
>To: 'Borland's Delphi Discussion List'
>Subject: RE: Component or Frame Arrays
>
>Oh,
>
>And I forgot. As to the array.
>
>Sure you can make an array if you want, static if you know that bound 
>or dynamic if not.
>
>Or a TList. That is what I would use.
>
>var
> frameList:TList;
>
>frameList:=TList.Create;
>
>..loop
>
>FuseList := TFrmFuse.Create(Self);
>frameList.Add(FuseList);
>with FuseList do
>
>
>And in the destroy or close of the form, walk the frameList and free 
>all the frames.
>
>Ciao,
>
>Mark
>

_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi


_______________________________________________
Delphi mailing list -> [email protected]
http://www.elists.org/mailman/listinfo/delphi

Reply via email to