unit Form.Main;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Rechner;
type
TForm1 =
class( TForm )
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure FormShow( Sender: TObject );
private
FIsLoading: Boolean;
FRechner: TRechner;
procedure SaveToRechner;
procedure LoadFromRechner;
procedure SyncWithRechner;
public
procedure AfterConstruction;
override;
procedure BeforeDestruction;
override;
published
procedure ControlChange( Sender: TObject );
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.AfterConstruction;
begin
inherited;
FRechner := TRechner.Create;
end;
procedure TForm1.BeforeDestruction;
begin
inherited;
FRechner.Free;
end;
procedure TForm1.ControlChange( Sender: TObject );
begin
SyncWithRechner;
end;
procedure TForm1.FormShow( Sender: TObject );
begin
LoadFromRechner;
end;
procedure TForm1.LoadFromRechner;
begin
if FIsLoading
then
Exit;
FIsLoading := True;
try
Edit1.Text := FRechner.Wert1;
Edit2.Text := FRechner.Wert2;
Edit3.Text := FRechner.Wert3;
Edit4.Text := FRechner.Wert4;
Label1.Caption := FRechner.Ergebnis1;
Label2.Caption := FRechner.Ergebnis2;
if FRechner.Wert3Berechnet
then
Edit3.Font.Color := clRed
else
Edit3.ParentFont := True;
finally
FIsLoading := False;
end;
end;
procedure TForm1.SaveToRechner;
begin
if FIsLoading
then
Exit;
FRechner.Wert1 := Edit1.Text;
FRechner.Wert2 := Edit2.Text;
FRechner.Wert3 := Edit3.Text;
FRechner.Wert4 := Edit4.Text;
end;
procedure TForm1.SyncWithRechner;
begin
SaveToRechner;
LoadFromRechner;
end;
end.