Solved

Use Delphi to add an integer to a Tedit name

Posted on 2015-02-20
3
238 Views
Last Modified: 2015-02-20
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
Comment
Question by:visionetv
3 Comments
 
LVL 13

Expert Comment

by:akb
ID: 40622278
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
 
LVL 19

Accepted Solution

by:
MerijnB earned 500 total points
ID: 40622447
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
 

Author Closing Comment

by:visionetv
ID: 40622590
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now