Solved

Use Delphi to add an integer to a Tedit name

Posted on 2015-02-20
3
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

751 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