| | |
[Delphi 3] using a var in object name.. "edit{i}"
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2009
Posts: 2
Reputation:
Solved Threads: 0
Hello
I am using Delphi 3.
I have 30 edit fields named e0, e1, e2, ..., e29. The thing is, that I want to put something into these edit fields, to be specific: I want to put variable a[0] into e0, a[1] into e1 and so on. i could of course write the same thing 30 times, but that takes time and is probably not the best way to do it.
So what I need is a way to call object names with variables. For example: (some pseudo-code)
Of course this will not work this way, but I think you can see what I am looking for now.
Is there any way to do this? It's not the first time it could come handy, but this time I really need it.
small offtopic question: is there any open source delphi sdk/ide? i'm kinda tired of delphi 3.
I am using Delphi 3.
I have 30 edit fields named e0, e1, e2, ..., e29. The thing is, that I want to put something into these edit fields, to be specific: I want to put variable a[0] into e0, a[1] into e1 and so on. i could of course write the same thing 30 times, but that takes time and is probably not the best way to do it.
So what I need is a way to call object names with variables. For example: (some pseudo-code)
Pascal and Delphi Syntax (Toggle Plain Text)
for i := 0 to 29 do e{i} := a[i];
Of course this will not work this way, but I think you can see what I am looking for now.
Is there any way to do this? It's not the first time it could come handy, but this time I really need it.
small offtopic question: is there any open source delphi sdk/ide? i'm kinda tired of delphi 3.
Last edited by laki4546; Nov 1st, 2009 at 3:26 pm.
•
•
Join Date: Oct 2009
Posts: 10
Reputation:
Solved Threads: 3
0
#2 Nov 2nd, 2009
Hi,
Personally i would be tempted to use the tag field in tEdit to enumerate each field.
With a form and 5 TEdits [Edit1..5] with tags 0..4
An Array A[0..4] of String
And a button
Put say a,b,c,d,e into your 5 Tedits and hit the button
procedure TForm1.Button1Click(Sender: TObject);
VAR
A : Array[0..4] OF String;
I : Integer;
T : TEdit;
begin
For i := 0 to ComponentCount - 1 DO
IF Components[i] IS TEdit
THEN
Begin
T := Components[i] as TEdit;
A[Components[i].Tag] := T.NAme + ' is ' + T.Text;
End;
For I := 0 to 4 DO
MessageDlg(A[i],MtInformation,[MbOK],0);
end;
Will result in 5 mes boxes: Edit1 is a, edit2 is b etc.
Hope that helps
P.
Personally i would be tempted to use the tag field in tEdit to enumerate each field.
With a form and 5 TEdits [Edit1..5] with tags 0..4
An Array A[0..4] of String
And a button
Put say a,b,c,d,e into your 5 Tedits and hit the button
procedure TForm1.Button1Click(Sender: TObject);
VAR
A : Array[0..4] OF String;
I : Integer;
T : TEdit;
begin
For i := 0 to ComponentCount - 1 DO
IF Components[i] IS TEdit
THEN
Begin
T := Components[i] as TEdit;
A[Components[i].Tag] := T.NAme + ' is ' + T.Text;
End;
For I := 0 to 4 DO
MessageDlg(A[i],MtInformation,[MbOK],0);
end;
Will result in 5 mes boxes: Edit1 is a, edit2 is b etc.
Hope that helps
P.
•
•
•
•
Hello
I am using Delphi 3.
I have 30 edit fields named e0, e1, e2, ..., e29. The thing is, that I want to put something into these edit fields, to be specific: I want to put variable a[0] into e0, a[1] into e1 and so on. i could of course write the same thing 30 times, but that takes time and is probably not the best way to do it.
So what I need is a way to call object names with variables. For example: (some pseudo-code)
Pascal and Delphi Syntax (Toggle Plain Text)
for i := 0 to 29 do e{i} := a[i];
Of course this will not work this way, but I think you can see what I am looking for now.
Is there any way to do this? It's not the first time it could come handy, but this time I really need it.
small offtopic question: is there any open source delphi sdk/ide? i'm kinda tired of delphi 3.
•
•
Join Date: Nov 2009
Posts: 40
Reputation:
Solved Threads: 4
0
#3 Nov 10th, 2009
Supposing the 30 TEdit are in a TPanel called Panel1, I would do it like this:
This is the most similar to your example it can get, but, I would do it a little more robust:
About a free pascal IDE+compiler, you have FreePascal + Lazarus, very delphi like and do compile for mac, linux, windows... even iPhone I read today!
The only bad things compared to delphi is that it takes much more time to compile (delphi is king here) and the exe file size is also much bigger.
Pascal and Delphi Syntax (Toggle Plain Text)
for i:= 0 to 29 do TEdit(Panel1.FindChildControl('E'+IntToStr(i))).Text:= a[i];
This is the most similar to your example it can get, but, I would do it a little more robust:
Pascal and Delphi Syntax (Toggle Plain Text)
for i:= 0 to 29 do begin MyEdit:= TEdit(Panel1.FindChildControl('E'+IntToStr(i))); if Assigned(MyEdit) then MyEdit.Text:= a[i]; end;
About a free pascal IDE+compiler, you have FreePascal + Lazarus, very delphi like and do compile for mac, linux, windows... even iPhone I read today!
The only bad things compared to delphi is that it takes much more time to compile (delphi is king here) and the exe file size is also much bigger.
•
•
Join Date: Nov 2009
Posts: 2
Reputation:
Solved Threads: 0
0
#4 Nov 12th, 2009
Thanks quaifp1 and BitFarmer for the solution!
I'm sorry for answering so late, but I have so much to do and are almost never at home in the week so I don't find much time to do other things.
Haven't tried it yet, but I will come back and ask if there were any problems. (although the structure looks relatively simple
)
As for Lazarus, I will try it, thanks for the tip. =D
I'm sorry for answering so late, but I have so much to do and are almost never at home in the week so I don't find much time to do other things.
Haven't tried it yet, but I will come back and ask if there were any problems. (although the structure looks relatively simple
)As for Lazarus, I will try it, thanks for the tip. =D
![]() |
Other Threads in the Pascal and Delphi Forum
- Previous Thread: Using Media Player
- Next Thread: insert data from dbgrid into SQL SERVER database table
Views: 866 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for delphi






