Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 381
  • Last Modified:

Use Delphi to add an integer to a Tedit name

Hi Experts;

Is it possible to add an integer to the name of a TEdit component from a loop? I'm trying to add an integer to the name of a number of edit boxes that contain various .text strings so I can iterate through the group and compare their text to a another string in another edit box... something like this:

For n := 1 to 40 do
begin
If Edit+IntToStr(n)+.text = Editbox1.text then
begin
(ShowMessage Edit+IntToStr(n) + 'is a match')
end;

The above of course does not work. There must be a way to do what should be a simple string comparison operation but apparently my approach is on the wrong track; any help would be appreciated.

Thank you,
Visionetv
0
visionetv
Asked:
visionetv
1 Solution
 
akbCommented:
Instead of adding an integer to the component name it would be easier to put your components into an array.

Instead of:
  EditBox1: TEdit;
  EditBox2: TEdit;
  EditBox3: TEdit;

Use:
  EditBox: array[1..3] of TEdit;
as a Public declaration.

Then use EditBox[n] in your program.

It's a while since I've used Delphi but hopefully this will point you in the right direction.
0
 
MerijnBSr. Software EngineerCommented:
This is a solution, which is not really fast, but if you don't do this too often (so not in a loop or something), it should work fine:

var Edit: TComponent;
    n: integer;
begin
 For n := 1 to 40 do
 begin
  Edit := FindComponent('Edit' + IntToStr(n));

  if (Edit is TEdit) then
   If TEdit(Edit).Text = Editbox1.text then
    ShowMessage('Edit' + IntToStr(n) + ' is a match');
 end;
end;

Open in new window

0
 
visionetvAuthor Commented:
MerijnB;

Thank you - application checks for duplicate entries in a Purchase Order form where all the fields are edit boxes. The form can have up to forty entries, so speed is not a problem.

Thanks again,
Visionetv
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now