Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#12

AW: Zustand eines Buttons erkennen

  Alt 20. Okt 2015, 14:02
Also mal ganz rudimentär würde ich so etwas vorschlagen:
Delphi-Quellcode:
unit Unit3;

interface

uses
  Winapi.Windows, Winapi.Messages,
  System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm3 = class( TForm )
    Value1Edit: TEdit; // Validate OnChange
    Value2Edit: TEdit; // Validate OnExit
    Value3Edit: TEdit; // Validate Button.OnClick
    Button1: TButton;
    Value1ErrorLabel: TLabel;
    Value2ErrorLabel: TLabel;
    Value3ErrorLabel: TLabel;
    procedure Value1EditChange( Sender: TObject );
    procedure Value2EditExit( Sender: TObject );
    procedure Button1Click( Sender: TObject );
  private
    FValue1Valid, FValue2Valid, FValue3Valid: Boolean;
    FValue1, FValue2, FValue3 : Integer;
    procedure ValidateValue1;
    procedure ValidateValue2;
    procedure ValidateValue3;
  public

  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

procedure TForm3.Value1EditChange( Sender: TObject );
begin
  ValidateValue1;
end;

procedure TForm3.Value2EditExit( Sender: TObject );
begin
  ValidateValue2;
end;

procedure TForm3.Button1Click( Sender: TObject );
begin
  ValidateValue1;
  ValidateValue2;
  ValidateValue3;

  if FValue1Valid and FValue2Valid and FValue3Valid
  then
    begin

    end;
end;

procedure TForm3.ValidateValue1;
begin
  FValue1Valid := TryStrToInt( Value1Edit.Text, FValue1 );
  if FValue1Valid
  then
    Value1ErrorLabel.Caption := ''
  else
    Value1ErrorLabel.Caption := 'not a valid number';
end;

procedure TForm3.ValidateValue2;
begin
  FValue2Valid := TryStrToInt( Value2Edit.Text, FValue2 );
  if FValue2Valid
  then
    Value2ErrorLabel.Caption := ''
  else
    Value2ErrorLabel.Caption := 'not a valid number';
end;

procedure TForm3.ValidateValue3;
begin
  FValue3Valid := TryStrToInt( Value3Edit.Text, FValue3 );
  if FValue3Valid
  then
    Value3ErrorLabel.Caption := ''
  else
    Value3ErrorLabel.Caption := 'not a valid number';
end;

end.
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)
  Mit Zitat antworten Zitat