1

TEdit の 3 つ、TButton の 1 つ、および文字列とブール変数の 3 つを含む単純なプロジェクトを作成しました。TEdit の各値が変更されたときに Button.Enable := True を設定するプロシージャまたは関数を作成する方法。以下のコードではなく、プロシージャまたは関数を作成してコーディングを減らす必要があります。

type
TForm1 = class(TForm)
  Edit1: TEdit;
  Edit2: TEdit;
  Edit3: TEdit;
  btnSave: TButton;
  procedure FormCreate(Sender: TObject);
  procedure Edit1Exit(Sender: TObject);
private
  { Private declarations }
public
  strWelcome, strTo, strThailand: String;
  modify1, modify2, modify3 : Boolean;
  { Public declarations }
end;

フォームの作成時に、3 つの文字列値を 3 つの TEdit.Text に割り当て、変更変数を False に設定します。

procedure TForm1.FormCreate(Sender: TObject);
 begin
   strWelcome := 'Welcome';
   strTo      := 'To';
   strThailand:= 'Thailand';

   modify1 := false;
   modify2 := false;
   modify3 := false;

   Edit1.text := strWelcome;
   Edit2.text := strTo;
   Edit3.text := strThailand;
end;

3 つの TEdit の 1 つの出口は、Edit1Exit(Sender: TObject) に割り当てます。テキスト値をチェックするために、まだ初期値に等しいかどうか? TEdit.Text の一部が変更された場合、btnSave が有効になります。

procedure TForm1.Edit1Exit(Sender: TObject);
begin
  if Edit1.Text = strWelcome then
    modify1 := False
  else
    modify1 := True;
  if Edit2.Text = strTo then
    modify2 := False
  else
    modify2 := True;
  if Edit3.Text = strThailand then
    modify3 := False
  else
    modify3 := True;
  btnSave.Enabled := modify1 or modify2 or modify3;
end;

上記のコードを削減するためのプロシージャまたは関数を作成するアイデア。:)

4

1 に答える 1