[fpc-devel] Problem (bug?) with generics
Bartosz Bogacz
bbartek at gmx.net
Thu Sep 13 20:04:02 CEST 2007
On Thursday 13 September 2007 16:47:38 Giulio Bernardi wrote:
You can make your own types in the generic class: (I changed your source a
bit)
> ===========================================================
>
> program genbug;
>
> {$MODE OBJFPC}
>
> uses
> Classes, SysUtils;
>
> type
> TRec32 = packed record
> data1 : longword;
> data2 : longword;
> end;
// PRec32 = ^TRec32;
>
> TRec64 = packed record
> data1 : qword;
> data2 : qword;
> end;
// PRec64 = ^TRec64;
>
generic TGenClass<_TRec_> = class
protected type
_TPRec_: ^_TRec_
> public
> constructor Create;
> end;
>
> TClass32 = specialize TGenClass<TRec32>;
> TClass64 = specialize TGenClass<TRec64>;
>
> constructor TGenClass.Create;
> var p : _TPRec_;
> begin
> GetMem(p,sizeof(_TRec_));
> p^.data1:=1;
> p^.data2:=2;
> FreeMem(p);
> end;
>
>
> begin
>
> end.
>
> ===========================================================
*Should* work now, I just wrote it form top of my head and did not test it.
More information about the fpc-devel
mailing list