Solved

How can I access a control name using strings?

Posted on 1998-11-23
5
129 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
[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
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
lortega earned 200 total points
ID: 1347696
var
 myName :STring

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

Expert Comment

by:lortega
ID: 1347697
ups...

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


0
 
LVL 2

Expert Comment

by:lortega
ID: 1347698
ups...

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


0
 
LVL 7

Expert Comment

by:ahalya
ID: 1347699
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
ID: 1347700
sorry, i didn't see the answers/comments when posting my comment.
0

Featured Post

Independent Software Vendors: 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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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