Einzelnen Beitrag anzeigen

Benutzerbild von maximov
maximov

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

Re: wie abspeichern?

  Alt 21. Jul 2004, 09:12
Moin.

Darfs vielleicht noch ein template sein? Womit die benutzung entgültig einfacher nicht geht und tausendmal praktischer als irgend ein array ist (zur funktionsweise der templates siehe links im code):

Delphi-Quellcode:
{$IFNDEF TYPED_DP_COLLECTION_TEMPLATE}
unit dpCollection_tmpl;

// written by MaxHub (maximov) 10.07.2004

// dpCollection: [url]http://www.delphipraxis.net/topic28945_tcollection+und+tcollectionitem.html[/url]

// thanks to Thomas Mueller for his 'Object Pascal Templates' article
// -> [url]http://www.dummzeuch.de/delphi/object_pascal_templates/deutsch.html[/url]

// thanks to Rossen Assenov for the original narticle 'Templates in Object Pascal'
// -> [url]http://community.borland.com/article/0,1410,27603,00.html[/url]

interface

uses Classes, dpCollection;


type
  _COLLECTION_ITEM_ = TCollectionItem;
{$ENDIF TYPED_DP_COLLECTION_TEMPLATE}

{$IFNDEF TYPED_DP_COLLECTION_TEMPLATE_SECOND_PASS}
type
  _COLLECTION_ = class (TmxJsCollection)
  protected
    function GetItem (const aIndex : Integer) : _COLLECTION_ITEM_;
    procedure SetItem (const aIndex : Integer;
                      const aValue : _COLLECTION_ITEM_);
    
  public
    constructor Create;

    function Add : _COLLECTION_ITEM_;
    function FindItemID (const aID : Integer) : _COLLECTION_ITEM_;
    function Insert (const aIndex : Integer) : _COLLECTION_ITEM_;
    property Items [const aIndex : Integer] : _COLLECTION_ITEM_ read GetItem write SetItem;
  end;


{$ENDIF TYPED_DP_COLLECTION_TEMPLATE_SECOND_PASS}

{$IFNDEF TYPED_DP_COLLECTION_TEMPLATE}
implementation
{$DEFINE TYPED_DP_COLLECTION_TEMPLATE_SECOND_PASS}
{$ENDIF TYPED_DP_COLLECTION_TEMPLATE}

{$IFDEF TYPED_DP_COLLECTION_TEMPLATE_SECOND_PASS}

{ TYPED_DP_COLLECTION }

constructor _COLLECTION_.Create;
begin
 inherited Create(_COLLECTION_ITEM_);
end;

function _COLLECTION_.Add : _COLLECTION_ITEM_;
begin
 Result := _COLLECTION_ITEM_ (inherited Add);
end;

function _COLLECTION_.FindItemID (const aID : Integer) : _COLLECTION_ITEM_;
begin
 Result := _COLLECTION_ITEM_ (inherited FindItemID (aID));
end;

function _COLLECTION_.GetItem (const aIndex : Integer) : _COLLECTION_ITEM_;
begin
 Result := _COLLECTION_ITEM_ (inherited GetItem (aIndex));
end;

function _COLLECTION_.Insert (const aIndex : Integer) : _COLLECTION_ITEM_;
begin
 Result := _COLLECTION_ITEM_ (inherited Insert (aIndex));
end;

procedure _COLLECTION_.SetItem (const aIndex : Integer;
                                const aValue : _COLLECTION_ITEM_);
begin
 inherited SetItem (aIndex, aValue);
end;

{$WARNINGS off}
{$IFNDEF TYPED_DP_COLLECTION_TEMPLATE}
end.
{$ENDIF TYPED_DP_COLLECTION_TEMPLATE}
{$ENDIF TYPED_DP_COLLECTION_TEMPLATE_SECOND_PASS}
{$DEFINE TYPED_DP_COLLECTION_TEMPLATE_SECOND_PASS}
Und einbinden kannst du es so:

Delphi-Quellcode:
interface

uses dpCollection, SysUtils, classes;

{!!! Hier die definitionen von jens -> TPatient etc. !!!}

{$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
  
...
mit der collection TPatienten kannst du kann alles machen und musst noch nicht mal casten
mâxîmôv.

{KDT}
  Mit Zitat antworten Zitat