Thema: Delphi a>=100

Einzelnen Beitrag anzeigen

Benutzerbild von Mavarik
Mavarik

Registriert seit: 9. Feb 2006
Ort: Stolberg (Rhld)
4.126 Beiträge
 
Delphi 10.3 Rio
 
#14

AW: a>=100

  Alt 19. Okt 2015, 15:38
Generells Problem bei dir: Datenhaltung in einer visuellen Komponente. Stichwort: Trennung von der Darstellung und der Datenverarbeitung.
Hast Du ein Beispiel wie man das getrennt hält?
Wenn ich dazu komme mache ich mal ein "richtiges" Beispiel...


Beispiel: (Bitte so nicht programmieren. Da fehlt noch ganz viel und auf man(n) nutzt keine festen Links... )

Form:

Delphi-Quellcode:
TForm1 = class(TForm)
    VorName: TEdit;
    PLZ: TEdit;
    Ort: TEdit;
    procedure AllChange(Sender: TObject);
  public
    Procedure Data2Form;
    Procedure Form2Data;
    { Public-Deklarationen }
  end;

 procedure TForm1.AllChange(Sender: TObject);
 begin
   Form2Data;
 end;

 Procedure TForm1.Data2Form;
 begin
   VorName.Text := StupidData.FVorName;
   PLZ.Text := StupidData.FPLZ;
   Ort.Text := StupidData.FOrt;
 end;

 Procedure TForm1.Form2Data;
 begin
   StupidData.FVorName := VorName.Text;
   StupidData.FPLZ := PLZ.Text;
   StupidData.FOrt := Ort.Text;
 end;
Und den Record...(Auch hier: Bitte nicht auf Form1 usw. zugreifen)
Soll nur ein Beispiel sein...

Delphi-Quellcode:
Type
   TStupidData = Record
                   FVorName : String;
                   FPLZ : String;
                   FOrt : String;
                   Procedure SetVorname(AValue : String);
                   Procedure SetPLZ(AValue : String);
                   Procedure SetOrt(AValue : String);
                   Property VorName : String write SetVorName;
                   Property PLZ : String write SetPLZ;
                   Property ORT : String write SetOrt;
                 end;

var
   StupidData : TStupiddata;

implementation

Procedure TStupidData.SetVorname(AValue : String);
begin
  FVorName := AValue;
  Form1.Data2Form;
end;

Procedure TStupidData.SetPLZ(AValue : String);
begin
  FPLZ := AValue;
  Form1.Data2Form;
end;

Procedure TStupidData.SetOrt(AValue : String);
begin
  FORT := AValue;
  Form1.Data2From;
end;
  Mit Zitat antworten Zitat