Passing control names to and from a function

How can I send a controls name to a procedure
I have 9 maskedEdit controls on a form taking integer values of a set limit say 40 if I enter 50 in any of the controls I would like to pass the name of the controls to a procedure so that a test can be carried out see below

a:= StrToInt(allowedA.caption)-(StrToInt(BayAM.text) + StrToInt(BayAC.text));{three controls to make sure value is not exceeded}
b:= BayAF.text;{value being entered ie Sender}
If (b = '') or (StrToInt(BayAF.text) > a) then
begin
BayAF.setFocus;
BayAF.text:='0';
Warning.caption:= 'Input Error 0 to ' + IntToStr(a);
end
Else  
end;

As you can see I need to send the controls name in which the value is entered this I can get by using Sender but I also need to send three other control names for the test.

next Question
#define in Delphi manual says that it can be done but does not tell you how any thoughts.

bgambellAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

florisbCommented:
Hmmm, no comprendo.

something like

procedure (var myControl: Twincontrol);
begin
if myControl is tedit then
  begin
  tedit(mycontrol).text := 'bla';
  tedit(myControl).setFocus;
  end;
end;

F.
0
edeyCommented:
how about this function to attach component pointers to names :)

FindComponent indicates whether or not a given component, AName, is owned by the component.

function FindComponent(const AName: string): TComponent;

l
mike
0
bgambellAuthor Commented:
Edited text of question.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

bgambellAuthor Commented:
Edited text of question.
0
RadlerCommented:
Hi bgambell;

If your question was clear to me is this what you look for

//** DFM
object Form1: TForm1
  Left = 286
  Top = 174
  Width = 663
  Height = 302
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object MaskEdit1: TMaskEdit
    Left = 16
    Top = 16
    Width = 121
    Height = 21
    TabOrder = 0
    Text = 'MaskEdit1'
    OnExit = MaskEdit1Exit
  end
  object MaskEdit2: TMaskEdit
    Left = 184
    Top = 24
    Width = 121
    Height = 21
    TabOrder = 1
    Text = 'MaskEdit2'
    OnExit = MaskEdit1Exit
  end
  object MaskEdit4: TMaskEdit
    Left = 352
    Top = 32
    Width = 121
    Height = 21
    TabOrder = 2
    Text = 'MaskEdit4'
    OnExit = MaskEdit1Exit
  end
  object MaskEdit5: TMaskEdit
    Left = 504
    Top = 24
    Width = 121
    Height = 21
    TabOrder = 3
    Text = 'MaskEdit5'
    OnExit = MaskEdit1Exit
  end
  object MaskEdit6: TMaskEdit
    Left = 24
    Top = 88
    Width = 121
    Height = 21
    TabOrder = 4
    Text = 'MaskEdit6'
    OnExit = MaskEdit1Exit
  end
  object MaskEdit7: TMaskEdit
    Left = 208
    Top = 88
    Width = 121
    Height = 21
    TabOrder = 5
    Text = 'MaskEdit7'
    OnExit = MaskEdit1Exit
  end
  object MaskEdit8: TMaskEdit
    Left = 384
    Top = 88
    Width = 121
    Height = 21
    TabOrder = 6
    Text = 'MaskEdit8'
    OnExit = MaskEdit1Exit
  end
  object MaskEdit9: TMaskEdit
    Left = 520
    Top = 88
    Width = 121
    Height = 21
    TabOrder = 7
    Text = 'MaskEdit9'
    OnExit = MaskEdit1Exit
  end
  object MaskEdit10: TMaskEdit
    Left = 264
    Top = 144
    Width = 121
    Height = 21
    TabOrder = 8
    Text = 'MaskEdit10'
    OnExit = MaskEdit1Exit
  end
  object BitBtn1: TBitBtn
    Left = 304
    Top = 208
    Width = 75
    Height = 25
    Caption = 'BitBtn1'
    TabOrder = 9
    OnClick = BitBtn1Click
  end
end


//Code
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    MaskEdit1: TMaskEdit;
    MaskEdit2: TMaskEdit;
    MaskEdit4: TMaskEdit;
    MaskEdit5: TMaskEdit;
    MaskEdit6: TMaskEdit;
    MaskEdit7: TMaskEdit;
    MaskEdit8: TMaskEdit;
    MaskEdit9: TMaskEdit;
    MaskEdit10: TMaskEdit;
    BitBtn1: TBitBtn;
    procedure MaskEdit1Exit(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.MaskEdit1Exit(Sender: TObject);
var
      ME : TMaskEdit;
      Value : integer;
begin
      ME:=TMaskEdit(Sender); //Simplify access
      try
            Value:=StrToInt(ME.Text);
      except
            ME.Text:='0'; //some error ???
            ME.SetFocus;
            MessageBeep( MB_ICONASTERISK ); //Alert
      end;
      if Value > 40 then begin  //Seems to be your condition
            ME.Text:='0';
            ME.SetFocus;
            MessageBeep( MB_ICONASTERISK ); //Alert
      end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
      MessageDlg( 'No errors - ?', mtInformation, [mbOK], 0);
end;

end.

"Happy to Help"

T++, Radler.
0
florisbCommented:
Errr, when you link them all to the same onClickEvent, you have the paramater Sender. With something like
b:= TMaskedEdit(Sender).text;

If you want to have a maskedit control with input limits, simple drop a tupDown on you form, set it property associate to your control and set the Min and Max property.

Floris.
0
RadlerCommented:
"Following the boat"

Use :
CompName:=TMaskEdit( Sender ).Name; //What the problem ???

But sincerally, I dont understand. You can put any criteria in my code to test.

Another hint, insisting at component name procedure is

TForm1.GetCompByName( const name : string ) : TComponent;
begin
  try
     Result:=Self.FindComponent( Name );
  except
    Result:=nil;
  end;
end;

Now make your rotine to use the code above to get the desired component.
Please make more comments to help us to help you.

T++, Radler.
0
gandalf_the_whiteCommented:
listening...
0
freterCommented:
try this:

TForm1.Edit1Change(Sender as TObject);
begin
  ShowMessage("User entered s.th. in edit control " + (Sender as TEdit).Name + "!";
end;

Assign this event procedure to all the edit controls you want to monitor and have fun :-)

</freter>
0
RadlerCommented:
Like you see everyone has the same answer bgambell.
Finally what is wrong with the first ?

T++, Radler.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RadlerCommented:
Thanks by consideration.

T--, Radler.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.