Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Common procedure for controls

Posted on 2009-05-15
9
183 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 14

Expert Comment

by:SteveBay
ID: 24399573
Too late :)
0
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

840 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