Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to assign multiple TEdit fields to variables Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
27-Aug-02
Category
VCL-General
Language
Delphi 2.x
Views
98
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

Is there an easier way to assign multiple Edit fields to variables without 
individually setting each one? Here is a sample code.

1   type
2     testrec = record
3       fees: array[1..10] of string[65];
4     end;
5   
6   var
7     dat: testrec;
8   
9   procedure FormToDat;
10  begin
11    fees[1] := Edit1.Text;
12    fees[2] := Edit2.Text;
13    fees[3] := Edit3.Text;
14    fees[4] := Edit4.Text;
15    { ... }
16  end;


This sample code seems inefficient and I'm thinking there might be an easier way to 
do this.

Answer:

There are a wide variety of ways to do this in Delphi, here's one:

17  var
18    I: Integer;
19    C: TComponent;
20  begin
21    for I := 1 to 10 do
22    begin
23      C := FindComponent('Edit' + IntToStr(I));
24      if C is TEdit then
25        TEdit(C).Text := Fees[1];
26    end;
27  end;


You could also store references to the edits in a TList or an array, or you could also iterate through the Controls or Components properties.

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC