Can I use a variable to name other variables?

Delphi 7 - variable in an object name?

  • I am looking for a way to make my objects follow each oder (each follows the previous one) in delphi 7. But I don't know how to use variables as the name of an object. to make all things clear: my objects names are s1,s2,s3 and so on "int" is a variable for how many objects I have. for i:= 2 to int do begin s+IntToSrt(int).left:=s+IntToStr(int-1).… s+InttoStr(int).top:=s+IntToStr(int-1).t… Of course this will not work this way, but I think you can see what I am looking for now. thank you

  • Answer:

    I would suggest you use an array of TObject (Generic) or typed objects if all your objects are the same type. An example might be something like the following: unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,   Dialogs, StdCtrls; type   TForm1 = class(TForm)     procedure FormCreate(Sender: TObject);   private     { Private declarations }   public     { Public declarations }     procedure OnClick(Sender: TObject);     procedure CreateButtons;   end; var   Form1: TForm1; implementation {$R *.dfm} var   MyObjects: array[0..10] of TButton; procedure TForm1.OnClick(Sender: TObject); begin   if (Sender is TButton) then     Showmessage('You clicked '+(Sender as TButton).Caption); end; procedure TForm1.CreateButtons; var i: integer; begin   for i:=0 to 10 do   begin     MyObjects[i] := TButton.Create(Self);     MyObjects[i].Parent := Self;     MyObjects[i].Caption := 'Button'+IntToStr(i);     MyObjects[i].Top := (MyObjects[i].Height * i);     MyObjects[i].Left := 2;     MyObjects[i].OnClick := OnClick; end; end; procedure TForm1.FormCreate(Sender: TObject); begin   CreateButtons; end; Hope this helps, but feel free to mail me ([email protected]) if needed. Mystic

Adam at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Use an array array[1..3] of TObject;

Rainmaker

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.