Link to home
Start Free TrialLog in
Avatar of JasonC
JasonC

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of lortega
lortega

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lortega
lortega

ups...

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


ups...

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


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...';


sorry, i didn't see the answers/comments when posting my comment.