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
Other answers
Use an array array[1..3] of TObject;
Rainmaker
Related Q & A:
- How to create deep object with dynamic name in Javascript?Best solution by Stack Overflow
- How to retrieve a variable name given its value?Best solution by Stack Overflow
- How to create variable from value in variable?Best solution by Stack Overflow
- How to use variable as Object Key?Best solution by Stack Overflow
- How to create an Object with multiple properties of the same name?Best solution by javascript.info
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.