[fpc-devel] Errors using generics - what is wrong?

Žilvinas Ledas ledas at liux.lt
Tue Oct 6 22:40:46 CEST 2009


Sorry, I forgot to mention I am using
Free Pascal Compiler version 2.3.1 [2009/09/08] for i386
(don't know how to get more specific version info...)



Žilvinas Ledas wrote:
> Hello all,
>
> I am trying to use generics but compilation fails.
> Whan I try to use unit with my generic class in my real project I get 
> "Fatal: Internal error 200204175" error.
> When I try to use it in empty Lazarus application (Unit1.pas) and I put
> -----
> procedure TForm1.Button1Click(Sender: TObject);
> var
>  lst:  specialize TTwoValuesList<UnicodeString>;
> begin
> end;
> -----
> I get these errors:
> -----
> Unit1.pas(29,17) Error: Forward declaration not solved "constructor 
> TTwoValuesList$UnicodeString.Create;"
> Unit1.pas(30,16) Error: Forward declaration not solved "destructor 
> TTwoValuesList$UnicodeString.Destroy;"
> Unit1.pas(32,15) Error: Forward declaration not solved 
> "TTwoValuesList$UnicodeString.AddString(UnicodeString,UnicodeString);"
> Unit1.pas(33,14) Error: Forward declaration not solved 
> "TTwoValuesList$UnicodeString.GetS1(LongInt):UnicodeString;"
> Unit1.pas(34,14) Error: Forward declaration not solved 
> "TTwoValuesList$UnicodeString.GetS2(LongInt):UnicodeString;"
> Unit1.pas(35,14) Error: Forward declaration not solved 
> "TTwoValuesList$UnicodeString.Count:LongInt;"
> Unit1.pas(36,14) Error: Forward declaration not solved 
> "TTwoValuesList$UnicodeString.GetS2(UnicodeString,Boolean="FALSE"):UnicodeString;" 
>
> Unit1.pas(47) Fatal: There were 7 errors compiling module, stopping
> -----
>
> my generic class is in another (not Unit1.pas) unit looks like this:
> -----
> type
>  generic TTwoValuesList<TVal> = class
>  type private
>    PTwoVal = ^TTwoVal;
>    TTwoval = record
>      FS1: TVal;
>      FS2: TVal;
>    end;
>
>  var private
>    FLst: TFPList;
>
>  public
>    constructor Create;
>    destructor Destroy;
>
>    procedure AddString(S1: TVal; S2: TVal);
>    function GetS1(i: Integer): TVal;
>    function GetS2(i: Integer): TVal; overload;
>    function Count: Integer;
>    function GetS2(S1: TVal; isSorted: Boolean = false): TVal; overload;
>
>  published
>    property Items: TFPList read FLst;
>
>  end;
> -----
>
> What am I doing wrong?
>
>
> Regards,
> Zilvinas Ledas
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-devel
>



More information about the fpc-devel mailing list