FCL/zh CN

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) suomi (fi) français (fr) Bahasa Indonesia (id) 日本語 (ja) русский (ru) 中文(中国大陆)‎ (zh_CN)

Free Component Library (FCL) 包含一组单元 (units), 用来提供完成常见任务的组件 (components)。它的设计使之尽可能与 Delphi 的 Visual Component Library (VCL) 相匹配, 但 FCL 仅限於提供非可视 (non-visual) 组件。另外, FCL 也超越了 VCL。

参阅 Free Component Library 页面可查看当前组件的当前开发状态, 以及所有可用的组件 (尽管它与 Lazarus 的 Reference for 'fcl' 似乎有所出入)。

您也可以查看 代码库 (source repository)。请注意 FCL 中也有一些平台相关的文件。


使用方法

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 the appropriate search path with a command-line compiler option of the form -Fu<path-to-fcl-units>.

当前 (future 2.2.2+) FCL 含有下列包:

文档

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

示例

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
   VObjectList: TObjectList; { for a list of objects; it is a reference to such a list! }
 
 begin
   VObjectList := TObjectList.Create  { create an empty list }
   with VObjectList do
   begin
     Add(TMyObject.Create('Thing One'));
     Writeln((Last as TMyObject).Name);
     Add(TMyObject.Create('Thing Two'));
     Writeln((Last as TMyObject).Name);
   end;
 end.

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

FCL 组件

This is not an exhaustive list (to avoid duplication of effort). It only mentions some important components, or components that are otherwise not easy to find.

Classes
Base classes for Object Pascal extensions in Delphi mode
Contnrs
Some common container classes
FPCUnit
Unit testing framework (based on Kent Beck's unit testing framework, e.g. cf. JUnit), documenting article about FPCUnit
XMLRead, XMLWrite and DOM
Detailed at the XML Tutorial