Solved

How can I access a control name using strings?

Posted on 1998-11-23
5
125 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
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

803 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