Difference between revisions of "FCL"

From Lazarus wiki
Jump to navigationJump to search
 
Line 1: Line 1:
 
+
The ''FreePascal Component Library'' (FCL) consists of a collection of units, providing components (mostly classes) for common tasks.
The "FreePascal Component Library" (FCL) consists of a collection of units, providing components (mostly classes) for common tasks.
+
It intends to be compatible with Delphi's ''Visual Component Library'' (VCL), but the FCL is restricted to non-visual components.
It intends to be compatible with Delphi's "Visual Component Library" (VCL), but the FCL is restricted to non-visual components.
 
 
On the other hand, the FCL also goes beyond the VCL.
 
On the other hand, the FCL also goes beyond the VCL.
  
Line 25: Line 24:
  
 
  program TObjectListExample;
 
  program TObjectListExample;
 
+
 
  uses
 
  uses
 
   Classes, { from RTL for TObject }
 
   Classes, { from RTL for TObject }
 
   Contnrs; { from FCL for TObjectList }
 
   Contnrs; { from FCL for TObjectList }
 
+
 
  type
 
  type
 
     TMyObject = class(TObject)  { just some application-specific class }
 
     TMyObject = class(TObject)  { just some application-specific class }
Line 38: Line 37:
 
       property Name: String read FName; { and a property to read the name }
 
       property Name: String read FName; { and a property to read the name }
 
   end;
 
   end;
 
+
 
  constructor TMyObject.Create(AName: String);
 
  constructor TMyObject.Create(AName: String);
 
  begin
 
  begin
Line 44: Line 43:
 
   FName := AName;
 
   FName := AName;
 
  end;
 
  end;
 
+
 
  var
 
  var
 
   VObject1, VObject2: TMyObject; { just some objects }
 
   VObject1, VObject2: TMyObject; { just some objects }
 
   VObjectList: TObjectList; { for a list of objects; s is a reference to such a list }
 
   VObjectList: TObjectList; { for a list of objects; s is a reference to such a list }
 
+
 
  begin
 
  begin
 
   VObject1 := TMyObject.Create('ThingOne');
 
   VObject1 := TMyObject.Create('ThingOne');

Revision as of 23:02, 3 June 2005

The FreePascal Component Library (FCL) consists of a collection of units, providing components (mostly classes) for common tasks. It intends to be compatible with Delphi's Visual Component Library (VCL), but the FCL is restricted to non-visual components. On the other hand, the FCL also goes beyond the VCL.

See FreePascal Component Library for the current development status and an overview of the available components. You can also check the source repository. Note that there are also some platform specific files in the FCL, which you can find under trunk/fcl/<platform>/.

Usage

To use an FCL component you need to include its name in a uses clause of your program or unit (see example below). The default compiler configuration is set up to search the fcl directory for such units. You can also set it with a command-line compiler option of the form -Fu<path-to-fcl-units>.

Documentation

Currently, the FCL is not documented (feel free to contribute). For Delphi compatible units, you could consult the Delphi documentation. You can always take a look at the source files in the source repository.

Example

The following program illustrates the use of the class TObjectList in the FCL unit Contnrs (providing various containers, including lists, stacks, and queues):

program TObjectListExample;

uses
  Classes, { from RTL for TObject }
  Contnrs; { from FCL for TObjectList }

type
   TMyObject = class(TObject)  { just some application-specific class }
   private
     FName: String; { with a string field }
   public
     constructor Create(AName: String); { and a constructor to create it with a given name }
     property Name: String read FName; { and a property to read the name }
  end;

constructor TMyObject.Create(AName: String);
begin
  inherited Create;
  FName := AName;
end;

var
  VObject1, VObject2: TMyObject; { just some objects }
  VObjectList: TObjectList; { for a list of objects; s is a reference to such a list }

begin
  VObject1 := TMyObject.Create('ThingOne');
  VObject2 := TMyObject.Create('ThingTwo');
  VObjectList := TObjectList.Create  { create an empty list }
  with VObjectList do
  begin
    Add(VObject1);
    Writeln((Last as TMyObject).Name);
    Add(VObject2);
    Writeln((Last as TMyObject).Name);
  end;
end.

This program must be compiled in an object-oriented mode, such as -Mobjfpc or -Mdelphi.