Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 03-29-2016, 03:16 AM
Badger Badger is offline
Member
 
Join Date: Aug 2013
Location: Sheffield, Tasmania (Aust)
Posts: 76
Default Procedure called by multiple components

I have a number of edit boxes that call a single procedure when changed. How do I write code within this procedure that only affects the sender?

I've tried things like sender.text:='OK' but it won't compile.

Badger
  #2  
Old 03-29-2016, 03:55 AM
rojam rojam is offline
Senior Member
 
Join Date: Jun 2015
Posts: 198
Default

Quote:
Originally Posted by Badger View Post
I have a number of edit boxes that call a single procedure when changed. How do I write code within this procedure that only affects the sender?

I've tried things like sender.text:='OK' but it won't compile.

Badger
If in fact all of the controls that will call this procedure are TEdit Controls then you can get by with
Code:
(Sender As TEdit).Text := 'OK';
or you could do
Code:
procedure TForm1.EditChange(Sender: TObject);
var
   Edit: TEdit;
begin
   Edit := Sender as TEdit;
   Edit.Text := 'OK';
end;
if there are other types of controls then you'll need to test to see which controls type is the sender.
Code:
if Sender is TEdit then
   (Sender As TEdit).Text := 'OK'
else if Sender is TLabel then
   (Sender As TLabel).Caption := 'OK';
You can also distinguish which controls is the one that caused the event to be fired
Code:
if Sender = Edit1 then
   Edit1.Text := 'OK'
else if Sender = Edit2 then
   Edit2.Text := 'OK';
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 05:29 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.