Solved

Common procedure for controls

Posted on 2009-05-15
9
181 Views
Last Modified: 2012-05-07
Hi Experts,

I have on a form a lot of editboxes (nearly 40). Each of them contains a short text. When the user clicks the editbox this editbox will be empty.

Type ebxName: TEdit;

procedure TfrmNew.ebxNameClick(Sender: TObject);
begin
   ebxName.Text:='';
end;

But I 'd like to have a common procedure for each editbox instead of the ~40 procedures.
Thanks for your support!
Janos
0
Comment
Question by:kacor
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 13

Expert Comment

by:rfwoolf
ID: 24399559
If you click on an edit box, and go into the object inspector, and click on the events tab, next to OnClick - you can put any valid procedure in there.

For example:

procedure TForm1.ClearEditBox(Sender : TObject);
begin
  if Sender is TEdit then
     Sender.Text := '';
end;

Then select all your edit boxes, go to events tab, under Onclick paste in 'ClearEditBox'

Hopefully that will solve your problem
0
 
LVL 22

Accepted Solution

by:
8080_Diver earned 167 total points
ID: 24399563
No problem.
You can use the Sender parameter to handle the problem for you.
I think I have the code correct in the snippet I am providing.   (I am in the middle of working on a commandline app and don't have the code where I do this sort of thing handy. ;-)
Just change the various OnClick events to all point to the one "ClearTextBoxClick" evenet handler.

procedure TfrmNew.ClearTextBoxClick(Sender: TObject);

begin

   TEdit(Sender).Text:='';

end;

Open in new window

0
 
LVL 14

Assisted Solution

by:SteveBay
SteveBay earned 166 total points
ID: 24399571
you can use the same event handler for all of your edit boxes
procedure TfrmNew.ebxNameClick(Sender: TObject);

begin

   TEdit(Sender).Text := '';

end;

Open in new window

0
 
LVL 14

Expert Comment

by:SteveBay
ID: 24399573
Too late :)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 22

Expert Comment

by:8080_Diver
ID: 24399590
Yup . . . by about 1 minute! ;-)
0
 
LVL 13

Assisted Solution

by:rfwoolf
rfwoolf earned 167 total points
ID: 24399617
Haha... I got it for once.
But I think 8080's (and SteveBay's) code is better - I didn't test mine, so go with this:
 if Sender is TEdit then
     TEdit(Sender).Text := '';
0
 
LVL 10

Author Closing Comment

by:kacor
ID: 31582098
Hi guys! Thanks for your quick help! Each solution is perfect!
Janos
0
 
LVL 22

Expert Comment

by:8080_Diver
ID: 24399862
rfwoolf,
Yours does have the advantage of making sure that the Send is a TEdit . . . however, since the developer has control over which cotrnols are calling the event handler, it would take a rather dimwitted developer to connect, for instance, a TRadioButton to the event handler (especially if it is named something like 'ClearTextBoxClick') . . . however, I have worked at places where I coded like that to prevent my co-workers from doing such silly things. ;-)
 
0
 
LVL 13

Expert Comment

by:rfwoolf
ID: 24400164
8080> LOL.  I hear you. However as I continue to grow as a developer, and as I further master object orientated programming, the philosophy seems to be to do stupid things like that. Just as you anticipate a user doing stupid things like entering letters when you ask for numbers or visa verse (you can of course use a TJvValidateEdit) or if it asks for whole numbers they can put fractions or decimals or if they leave something blank, or if they put a negative number  etc. -- so too should we consider that developers might use this procedure incorrectly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 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

15 Experts available now in Live!

Get 1:1 Help Now