Solved

Use Delphi to add an integer to a Tedit name

Posted on 2015-02-20
3
329 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month10 days, 1 hour left to enroll

624 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