(Moderator)
Registriert seit: 9. Dez 2005
Ort: Heilbronn
39.861 Beiträge
Delphi 11 Alexandria
|
AW: Generics in Record
2. Sep 2010, 14:55
Versuch es mal mit Klassen. So scheint es zu gehen
Delphi-Quellcode:
unit GTU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
TRecObj<T> = class
type
//PRec = ^TRec;
TRec = class
ID: integer;
Data: T;
end;
private
FRec: TRec;
public
constructor Create(ID: integer; Data: T);
destructor Destroy; reintroduce;
end;
var
Form1: TForm1;
myObj: TRecObj< string>;
implementation
{$R *.dfm}
constructor TRecObj<T>.Create(ID: integer; Data: T);
begin
inherited Create;
FRec := TRec.Create;
FRec.ID := ID;
FRec.Data := Data; // schmeißt AV
end;
destructor TRecObj<T>.Destroy;
begin
FRec.Destroy;
inherited Destroy;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
myObj := TRecObj< string>.Create(-17, ' Hallo');
Caption := myObj.FRec.Data;
end;
end.
Markus Kinzler
Geändert von mkinzler ( 2. Sep 2010 um 15:00 Uhr)
|
|
Zitat
|