AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

TObjectList und Generics --> E2515

Ein Thema von GreenHorn3600 · begonnen am 25. Okt 2008 · letzter Beitrag vom 26. Okt 2008
 
GreenHorn3600

Registriert seit: 24. Jun 2007
165 Beiträge
 
#1

TObjectList und Generics --> E2515

  Alt 25. Okt 2008, 18:38
Hallo Jungs,

ich versuche mich gerade mit den Generics. Doch bis an hin leider erfolglos. Der Kompiler meint nur dazu

Code:
[DCC Fehler] Unit1.pas(42): E2515 Typparameter 'TKey' ist mit Typ 'TC1' nicht kompatibel
[DCC Fehler] Unit1.pas(55): E2010 Inkompatible Typen: 'TKey' und 'TObject'
[DCC Fehler] Unit1.pas(64): E2515 Typparameter 'TKey' ist mit Typ 'TC1' nicht kompatibel
[DCC Fataler Fehler] Project1.dpr(5): F2063 Verwendete Unit 'Unit1.pas' kann nicht compiliert werden
Kennt jemand das Problem und weiss jemand eine Lösung? Hier mein vergeblicher Versuch:
Delphi-Quellcode:
type
  TC1 = class
    aValue: string;
  end;
  tc2 = class
    aValue: string;
  end;
  tcl<TKey: class> = class(tObjectList)
   private
     function GetItem(Index: integer): TKey;
     procedure SetItem(Index: integer; const Value: TKey);
   public
     property Items[Index: integer]: TKey read GetItem write SetItem;
  end;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    l1: tcl<tc1>;
    l2: tcl<tc2>;
  end;

var
  Form1: TForm1;

implementation
{$R *.dfm}

function tcl<TKey>.GetItem(Index: integer): TKey;
begin
  result := inherited items[index];
end;
procedure tcl<TKey>.SetItem(Index: integer; const Value: TKey);
begin
  inherited items[index] := value;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
  l1 := tcl<tc1>.create;
  l2 := tcl<tc2>.create;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
  if l1 <> NIL then FreeAndnIL(l1);
  if l2 <> NIL then FreeAndNIL(l2);
end;
Der Create scheint ihm gar nicht zu gefallen

Vielen Dank schon Mal
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:13 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz