Re: [fpc-pascal] Generics Compile Error, 2.4.2 vs 2.6.0

2012-02-13 Thread David Copeland
Thanks very much. It now compiles! 

Dave.




-Original Message-
From: J.-c. Chu 
Reply-to: FPC-Pascal users discussions 
To: FPC-Pascal users discussions 
Subject: Re: [fpc-pascal] Generics Compile Error, 2.4.2 vs 2.6.0
Date: Tue, 14 Feb 2012 00:59:03 +0800

If you are compiling the unit in Delphi mode, you’ll need to use the
syntax of Delphi.

*  Generics are defined without the GENERIC keyword.
*  Generics are specialized without the SPECIALIZE keyword.
*  To define class-local types and variables, visibility specifiers need
   to be placed before the TYPE and VAR keywords.
*  Implementations of the methods of a generic class must include the
   type parameters of the class.

Please check if the attached file works.





___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Generics Compile Error, 2.4.2 vs 2.6.0

2012-02-13 Thread J.-c. Chu
If you are compiling the unit in Delphi mode, you’ll need to use the
syntax of Delphi.

*  Generics are defined without the GENERIC keyword.
*  Generics are specialized without the SPECIALIZE keyword.
*  To define class-local types and variables, visibility specifiers need
   to be placed before the TYPE and VAR keywords.
*  Implementations of the methods of a generic class must include the
   type parameters of the class.

Please check if the attached file works.


On February 14, 2012, David Copeland wrote:

> Under FPC 2.4.2 I have been using RBTree unit that uses generics. With
> 2.6.0 it fails to compile. I know that there have been changes for 2.6.0
> but I have checked the syntax in the 2.6.0 Language Reference and cannot
> see why the error is occurring. I have also looked in Mantis but don't
> know if anything there relates to my problem. I have excerpted the code
> below and attached the complete unit.
> 
> ==
> 
> unit FOS_REDBLACKTREE_GEN;
> 
> // (c) Copyright FirmOS Business Solutions GmbH
> // Author Helmut Hartl, Franz Schober
> 
> }
> //{$MODE OBJFPC}
> {$MODE DELPHI}
> {$H+}
> 
> interface
> 
> type
>   TRB_NodeColor=(R,B);
> 
>   { TGFOS_RBTree }
>   {$B-}
>   generic TGFOS_RBTree<_TKey,_TStore> = class(TInterfacedObject)
> 
> *** The error occurs at the line above.
> 
> Free Pascal Compiler version 2.6.0 [2012/02/08] for x86_64
> Copyright (c) 1993-2011 by Florian Klaempfl and others
> Target OS: Linux for x86-64
> Compiling FOS_REDBLACKTREE_GEN.pas
> FOS_REDBLACKTREE_GEN.pas(48,11) Fatal: Syntax error, "=" expected but
> "identifier TGFOS_RBTREE" found
> Fatal: Compilation aborted
> 
> 
> type public
>   PFOS_RB_NodeG=^TFOS_RB_NodeG;
>   _PStore   =^_TStore;
>   TFOS_RB_NodeG = packed record
>   k:  _TKey;
>   left, right, parent: PFOS_RB_NodeG;
>   col: TRB_NodeColor;
>   val:_TStore;
>end;
>TCompareKeys = function  (const Item1, Item2: _TKey):
> Integer;
>TGUndefined  = function  :_Tstore;
>TGUndefinedKey   = function  :_TKey;
>TGFOS_RB_OnItem  = procedure (const Item:_TStore) of object;
>TGFOS_RB_OnItemN = procedure (const Item:_TStore);
> 
> 
> ==
> 
> Thanks for any help.
> 
> 
> 
> 
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal

-- 
Best Regards,
J.-c. Chu
unit FOS_REDBLACKTREE_GEN;

// (c) Copyright FirmOS Business Solutions GmbH
// Author Helmut Hartl, Franz Schober

{ // New Style BSD Licence (OSI)

Copyright (c) 2001-2009, FirmOS Business Solutions GmbH
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
* Neither the name of the  nor the names
  of its contributors may be used to endorse or promote products derived
  from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

}
//{$MODE OBJFPC}
{$MODE DELPHI}
{$H+}

interface

type
  TRB_NodeColor=(R,B);

  { TGFOS_RBTree }
  {$B-}
  TGFOS_RBTree<_TKey,_TStore> = class(TInterfacedObject)
  public
type
  PFOS_RB_NodeG=^TFOS_RB_NodeG;
  _PStore   =^_TStore;
  TFOS_RB_NodeG = packed record
  k:  _TKey;
  left, right, parent: PFOS_RB_NodeG;
  col: TRB_NodeColor;
  val:_TStore;
   end;
   TCompareKeys = function  (const Item1, Item2: _TKey): Integer;
   TGUndefined  = function  :_Tstore;
   TGUndefinedKey   = function  :_TKey;
   TGFOS_RB_OnItem  = procedure (const Item:_TStore) of object;
   TGFOS_RB_OnItemN = procedure (const Item:_TStore);
  private
var
  _Count:QWord;
  _Compare:  TCompareKeys;
  _Undef:TGUndefined;
  _UndefKey: TGUndefinedK