Solved

Common procedure for controls

Posted on 2009-05-15
9
177 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

10 Experts available now in Live!

Get 1:1 Help Now