Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#9

Re: Verwalten von Objekten in einer Container-Klasse

  Alt 13. Mär 2007, 16:34
Ich habe es jetzt so:
Delphi-Quellcode:
type
  TContact = class(TObject)
  private
    FFirstName: String;
    FLastName: String;
    function GetFirstName: String;
    procedure SetFirstName(const Value: String);
    function GetLastName: String;
    procedure SetLastName(const Value: String);
  public
    property FirstName: String read GetFirstName write SetFirstName;
    property LastName: String read GetLastName write SetLastName;
  end;

  TContactList = class(TObject)
  private
    FInnerList: TList;
    function GetItem(Index: Integer): TContact;
    procedure SetItem(Index: Integer; Contact: TContact);
    function GetCount: Integer;
  public
    constructor Create;
    destructor Destroy; override;
    procedure Add(Contact: TContact);
    procedure Delete(Index: Integer);
    property Count: Integer read GetCount;
    property Items[Index: Integer]: TContact read GetItem write SetItem;
  end;

  TAddressBook = class(TObject)
  private
     FContacts: TContactList;
  public
    constructor Create;
    destructor destroy; override;
    property Contacts: TContactList read FContacts write FContacts;
  end;
Aber hier:
Delphi-Quellcode:
procedure TContactList.Delete(Index: Integer);
begin
  // destroy object
  FInnerList.Items[Index].Free;
  FInnerList.Items[Index] := nil;
  // delete object from the list
  FInnerList.Delete(Index);
end;
sagt er mir in Zeile 4:
Zitat:
[Error] AddressBookCls.pas(106): Record, object or class type required
Er kennt also das Free nicht. Warum das nicht?
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat