Einzelnen Beitrag anzeigen

Benutzerbild von maximov
maximov

Registriert seit: 2. Okt 2003
Ort: Hamburg
548 Beiträge
 
Delphi 2005 Professional
 
#29

Re: wie abspeichern?

  Alt 21. Jul 2004, 23:21
OK! Zum mitschreiben

Delphi-Quellcode:
unit patient_impl;

interface

uses dpCollection, SysUtils, classes;


Type

  TZustand = class(TPersistent)
  private
    FAtem: Integer;
    FHerzschlag: Integer;
  public
    procedure Assign(Source : TPersistent); override; // Sollte immer überschrieben werden
  published
    property Atem : Integer read FAtem write FAtem default 0;
    property Herzschlag : Integer read FHerzschlag write FHerzschlag default 0;
  end;

  TPatient = class(TCollectionItem)
  private
    FLaufText : String;
    FName : String;
    FTipps : TStrings;
    FStory : TStrings;
    FZustand : TZustand;
    procedure SetStory(const Value: TStrings);
    procedure SetTipps(const Value: TStrings);
    procedure SetZustand(const Value: TZustand);
  public
    constructor Create(Collection : TCollection); override;
    destructor Destroy; override;
    procedure Assign(Source : TPersistent); override; // Sollte immer überschrieben werden
  published
    property Name : String read FName write FName;
    property LaufText : String read FLaufText write FLaufText;
    property Story : TStrings read FStory write SetStory;
    property Tipps : TStrings read FTipps write SetTipps;
    property Zustand : TZustand read FZustand write SetZustand;
  end;


// mit dem einbinden des templates erzeugst du eine collection,
// die auf deine eigene item-klasse spezialisiert ist.
// Du musst nix mehr casten!!!

{$define TYPED_DP_COLLECTION_TEMPLATE} 
type
  _COLLECTION_ITEM_ = TPatient; // typ der collectionItems festlegen
  {$INCLUDE 'dpCollection_tmpl.pas'}  // typisierte collection generieren
  TPatienten = _COLLECTION_; // fertige collection eine sprechenden namen geben

implementation

{$INCLUDE dpCollection_tmpl.pas}

{ TZustand } 

procedure TZustand.Assign(Source: TPersistent);
begin
  If Source is TZustand then
    begin
    FAtem:=TZustand(Source).Atem;
    FHerzschlag:=TZustand(Source).Herzschlag;
    end;
  inherited Assign(Source);
end;

{ TPatient } 

procedure TPatient.Assign(Source: TPersistent);
begin
  If Source is TPatient then
    begin
    FLaufText:=TPatient(Source).LaufText;
    FName:=TPatient(Source).Name;
    FTipps.Assign(TPatient(Source).Tipps);
    FStory.Assign(TPatient(Source).Story);
    FZustand.Assign(TPatient(Source).Zustand);
    end;
  inherited Assign(Source);
end;

constructor TPatient.Create(Collection: TCollection);
begin
  inherited Create(Collection);
  FZustand:=TZustand.Create;
  FTipps:=TStringList.Create;
  FStory:=TStringList.Create;
end;

destructor TPatient.Destroy;
begin
  FStory.Free;
  FTipps.Free;
  FZustand.Free;
  inherited Destroy;
end;

procedure TPatient.SetStory(const Value: TStrings);
begin
  FStory.Assign(Value);
end;

procedure TPatient.SetTipps(const Value: TStrings);
begin
  FTipps.Assign(Value);
end;

procedure TPatient.SetZustand(const Value: TZustand);
begin
  FZustand.Assign(Value);
end;

end.
...ok. hatte das include im implementation-teil vergessen. Das hättest du aber schnell gesehen, wenn du dir mal die links angesehen hättest. Schwamm drüber. Funktionert super! Und zwar so:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, patient_impl;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    collection:TPatienten;
  end;

var
  Form1: TForm1;

implementation



{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  collection:=TPatienten.Create;
  with collection.Add do
  begin
    Name := 'horst';
    LaufText := '...';
    Zustand.Atem := 42;
    Zustand.Herzschlag := 180;
  end;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  collection.saveTiFile('c:/patienten.db.txt.dfm');
  collection.Free;
end;

end.

hoffe jetzt wirds klarer?
mâxîmôv.

{KDT}
  Mit Zitat antworten Zitat