Home > Back-end >  How can I use button component, assignment of multiple Edit respectively
How can I use button component, assignment of multiple Edit respectively

Time:09-16

Press the button to Edit1 assignment 1 to do how to call a function after Edit2

CodePudding user response:

Write a generic function, according to the input parameters, respectively to different edit assignment
Fun (type: intger)
The begin
If type=1 then
Edit1. Text:='1';
If tyep=2 then2
Edit2. Text:='2';
end

CodePudding user response:

Use the tag property of the control and dynamic binding events, can write very general,
Key point: TEdit. TButton and tag. The tag is set to the same value, for the same group, or through controls the name value, according to certain rules,

 
The unit Unit1;

Interface

USES the
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

Type
TForm1=class (TForm)
Edit1: TEdit;
For: TButton;
Edit2: TEdit;
Button2: TButton;
Procedure FormCreate (Sender: TObject);
Private
{Private declarations}
Procedure OnSetValue (sender: TObject);
Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}

Procedure TForm1. FormCreate (Sender: TObject);
The begin
For the OnClick:=OnSetValue;
Button2. OnClick:=OnSetValue;
//if you have more control, continue to dynamic binding events
end;

Procedure TForm1. OnSetValue (sender: TObject);
Var
I: integer;
The begin
For I:=0 to do ControlCount - 1
The begin
If (Controls, [I] is TEdit) and TEdit (Controls, [I]). The Tag=TButton (sender). The Tag then
The begin
TEdit (Controls, [I]). The Text:=TButton (sender). Caption + 'clicked';//edit assignment
end;
end;
end;

End.

  • Related