[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 134
  • Last Modified:

How can I access a control name using strings?

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
JasonC
Asked:
JasonC
  • 3
  • 2
1 Solution
 
lortegaCommented:
var
 myName :STring

MyName := (Sender as TEdit).name
0
 
lortegaCommented:
ups...

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


0
 
lortegaCommented:
ups...

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


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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now