Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

onExit function get name of component that called it

Posted on 2006-07-12
6
Medium Priority
?
232 Views
Last Modified: 2011-09-20
I'm building a funtion for when my user exits an editbox I want this same function to be called for all of my editboxes.  This is probably easy to do but I don't know how to get the name of the component that's calling the function.  So if I exit editbox1 how do I get editbox1's name in my procedure.

ex.

procedure TForm1.EditFieldExit(Sender: TObject);
begin

    //figure out which edit box called this function
   //change properties of that specific editbox ie Color
end;
0
Comment
Question by:ICPooreman
[X]
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
  • 3
  • 2
6 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17090654
procedure TForm1.EditFieldExit(Sender: TObject);
begin

  if (Sender is TCustomEdit) then
  begin
     with TCustomEdit(Sender) do
        ShowMessage(Name);
  end;

end;

Regards,
Russell
0
 

Author Comment

by:ICPooreman
ID: 17090824
That's giving me the Name of the form, I'm looking into how to access and change properties of the editbox that's calling the procedure.

Your function shows the message 'form1' where as I want to be able to find and manipulate 'editbox1'.  Maybe I'm missing a simple step.
0
 
LVL 6

Accepted Solution

by:
House_of_Dexter earned 500 total points
ID: 17090857
 if (Sender is TEdit) then
  begin
    if TEdit(Sender).Name = 'Edit1' then TEdit(Sender).Font.Color  := clBlue else
    if TEdit(Sender).Name = 'Edit2' then TEdit(Sender).Font.Color  := clRed else
    if TEdit(Sender).Name = 'Edit3' then TEdit(Sender).Font.Color  := clGreen;
  end;
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 6

Expert Comment

by:House_of_Dexter
ID: 17090904
you probably forgot the   with TCustomEdit(Sender) do
        ShowMessage(Name);

thats one of the reasons I hate WITH...instead do this...
TCustomEdit(Sender).Name or

var
  a_CustomeEdit: TCustomEdit;

begin
  if (Sender is TCustomEdit) then
  begin
     a_CustomomEdit := Sender;
   ShowMessage( a_CustomomEdit .Name);
  end;

end;



0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17090911
It should not be returning the form's name (at least its not for me). You can change it to:

procedure TForm1.EditFieldExit(Sender: TObject);
begin

  if (Sender is TCustomEdit) then
  begin
     ShowMessage(TCustomEdit(Sender).Name);
  end;

end;

just to ensure that the .Name resolves to the edit control, but the OnExit event (exposed from TWinControl) always passes Self as the sender, so this should be working as long as you have the EditFieldExit procedure bound to all of the OnExit events for the edits. Full example below:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    procedure Edit1Exit(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Edit1Exit(Sender: TObject);
begin

  if (Sender is TCustomEdit) then
  begin
     ShowMessage(TCustomEdit(Sender).Name);
  end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin

end;

end.

-- dfm --
object Form1: TForm1
  Left = 353
  Top = 205
  Width = 406
  Height = 203
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 28
    Top = 28
    Width = 121
    Height = 21
    TabOrder = 0
    Text = 'Edit1'
    OnExit = Edit1Exit
  end
  object Edit2: TEdit
    Left = 28
    Top = 60
    Width = 121
    Height = 21
    TabOrder = 1
    Text = 'Edit2'
    OnExit = Edit1Exit
  end
  object Edit3: TEdit
    Left = 28
    Top = 88
    Width = 121
    Height = 21
    TabOrder = 2
    Text = 'Edit3'
    OnExit = Edit1Exit
  end
  object Button1: TButton
    Left = 184
    Top = 24
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 3
  end
end



Russell

0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17090926

It also helps if people read what has been written.

Russell
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

609 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