Solved

How can I access a control name using strings?

Posted on 1998-11-23
5
123 Views
Last Modified: 2010-04-04
I want to be able to use a piece of code for several controls and use the 'Sender' information to accomplish this.

The code looks like this...

>>procedure TMyForm.udnLabelWidthUpClick(Sender: TObject);
>>begin
>>txtLabelWidth.Text := Floattostr(strtoFloat(txtLabelWidth.Text) + (1 / MeasureScale));
>>end;

I would like to be able to access the 'txtLabelWidth' control using the name of the 'UpDown' control. i.e. removing the first three letters of the 'udnLabelWidth' and adding 'txt' to it. And then use the string to access the control.

Thanks in advance
0
Comment
Question by:JasonC
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
lortega earned 200 total points
Comment Utility
var
 myName :STring

MyName := (Sender as TEdit).name
0
 
LVL 2

Expert Comment

by:lortega
Comment Utility
ups...

then
if  MyName = 'Upn...'
    then...{Do in one way}
    else...{Do in another way}


0
 
LVL 2

Expert Comment

by:lortega
Comment Utility
ups...

then
if  MyName = 'Upn...'
    then...{Do in one way}
    else...{Do in another way}


0
 
LVL 7

Expert Comment

by:ahalya
Comment Utility
following code spinpet would work assuming that you are using "SpinButtons". you can modify it as needed:

if (Sender is TSpinButton) then s := (Sender as TSpinButton).Name;
delete(s, 1, 3);
insert('txt', s, 1);
C := FindComponent(s);
(C as TEdit).Text := 'whatever...';


0
 
LVL 7

Expert Comment

by:ahalya
Comment Utility
sorry, i didn't see the answers/comments when posting my comment.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

13 Experts available now in Live!

Get 1:1 Help Now