Lazarus cannot find Uses Generics

2.9k Views Asked by At

Why can't I uses Generics.Collections or Generics.Default or even just Generics in Lazarus?

Uses
  Generics.Collections;

Uses
  System.Generics.Default;

Uses
  System.Generics.Collections;

Uses
  System.Generics.Default,
  System.Generics.Collections;

Uses
  SysUtils,
  Generics;    

Cannot find Generics.Collections used by uTest of the Project Inspector.
Cannot find Generics.Defaults used by uTest of the Project Inspector.
Cannot find Generics used by uTest of the Project Inspector.

4

There are 4 best solutions below

0
Remy Lebeau On BEST ANSWER

Lazarus is the IDE for the open-source FreePascal compiler. Neither of them have ANYTHING to do with Delphi. FreePascal is a completely separate Pascal compiler than the one Delphi uses.

FreePascal has a Delphi compatibility mode, and does implement various Delphi units and classes, to help users port existing Delphi code to FreePascal.

But as far as Generics is concerned, FreePascal provides its own Generics syntax and implementation that is different from, and not compatible with, Delphi's Generics (actually, support for Delphi-style Generics was added in FreePascal 2.6, but "still may be not 100% compatible" with Delphi. Also see delphi language features which fpc does not have - Generics Syntax).

Read FreePascal's documentation for more details about its flavor of Generics:

http://wiki.freepascal.org/Generics

http://www.freepascal.org/docs-html/ref/refch8.html

The System.Generics.Default and System.Generics.Collections units are only available in Delphi, they do not exist in FreePascal. However, there is a 3rd party implementation of these units available for FreePascal.

0
HNB On

Generics.Collections library (with Generics.Defaults module) has been added to FPC trunk as rtl-generics package in r34229. Latest version of precompiled FPC trunk (with Generics.Collections) for Win32 + Lazarus trunk available at http://newpascal.org . The repository of Generics.Collections ( https://github.com/dathox/generics.collections ) will be still used for maintenance (should be synced often with FPC trunk).

0
Jacek Krawczyk On

I recomend you to use the Generics.Collections package made by Maciej Izak.

0
J. Pablo García On

OPTION 1: Try installing Sparta/generics from Lazurus packages installer form (I don't know if it is possible).

OPCION 2: intalling this manualy.

I did it by doing this (may be not the best way):

  1. Download the .zip from here
  2. I unzipped in c:/temporal
  3. And from the command line in that path do: "fpc fpmake.pp" + ENTER, which should generate "fpmake.exe".
  4. Double click on fpmake.exe

It seems like this is installing the component on lazarus/components/sparta/generics, the problem is that you cannot access it from Lazarus Packages Installer form.

OPTION 3: If it is not possible, you can try this way if it is just for one project (not the good way but it worked for me):

  1. Download the .zip from here
  2. Copy the "src" folder at some place and rename it (i.e.: src_generic)
  3. Add that path in "project/options" => "Paths" (sorry mine is in Spanish). enter image description here