Referência
Folha de consulta
A sintaxe mais usada, lado a lado, para consulta rápida.
Todos os trechos abaixo aparecem, completos e verificados, nas páginas de A linguagem.
Programa, módulo e biblioteca#
program Hello; // .fxp → .exe
uses System.Remainder;
begin
WriteLn('Olá, mundo!');
end.module Geometry; // .fxm
public const Sides = 4; // omissão: private
public function SquareArea(const ASide: Int32): Int32;
begin
Exit(ASide * ASide);
end function;
initialization
…
end.library Greeter; // .fxp → .dll
function Add(A, B: Int32): Int32; stdcall;
begin Exit(A + B); end function;
exports Add, Square name 'SquareRenamed';
begin
end.Declarações#
const Limit = 3; Greeting: UString = 'olá';
type TColor = (Red, Green, Blue); TColors = set of TColor;
var Total: Int32 = 100; Fresh: default Int32;
Names: array[0..2] of UString; Dyn: array of Int32;
P: ^Int32; Big: Int256; Price: Currency64;Comandos#
if X > 0 then … else …; case I of 0..4: …; 5, 6: …; else …; end case;
for I := 1 to N do …; for I := N downto 1 do …;
for var K in 0..3 do …; for X in Items do …; for X downin Items do …;
while C do …; repeat … until C;
for [outer] I := 1 to 3 do for [inner] J := 1 to 3 do Break(outer);
Q, R := 17 divmod 5;
V := if C then A else B; V := C ? A : B;
scase S of 'a': …; end scase; icase S of 'A': …; end icase;
with NewItem(7) as It do It.Value := 1;
try … except on E: EValidation do … end try; try … finally … end try;
raise EValidation.Create('msg'); raise 'só o texto';Rotinas#
function Fib(N: Int32): Int32;
procedure Swap(var A, B: Int32);
procedure Split(const V, D: Int32; out Q, R: Int32);
procedure Greet(const AName: UString = 'mundo');
function Describe(const N: Int32): UString; overload;
function GetTickCount: UInt32; stdcall; external 'kernel32.dll' name 'GetTickCount';Classes, records e interfaces#
type
TAnimal = class(TObject, IShape)
private
FName: UString;
public
constructor Create(const AName: UString);
destructor Destroy; override;
procedure Speak; virtual; abstract;
function Area: Int32; => Exit(FSide * FSide);
property Name: UString read FName write FName;
property Item[const I: Int32]: Int32 read GetItem write SetItem;
end class;
TPoint = record
X, Y: Int32;
constructor Create(const AX, AY: Int32);
class operator Add(const A, B: TPoint): TPoint; => Exit(TPoint.Create(A.X + B.X, A.Y + B.Y));
end record;
TGuard = managed record
class operator Initialize(out D: TGuard); => …;
class operator Finalize(var D: TGuard); => …;
end record;
{$config InterfaceExtendedSyntax on}
IShape = interface(IInterface)
function Area: Int32; virtual;
end interface;
TInt32Helper = helper for Int32
function Double: Int32;
end helper;Genéricos, lambdas, async#
TStack<T> = class(TObject) … end class; TFactory<T: class, constructor> = class(TObject) … end class;
function Larger<T>(const A, B: T): T; Larger<Int32>(3, 9);
type TBinary = reference to function(A, B: Int32): Int32;
var Sum := function(A, B: Int32): Int32; begin Exit(A + B); end function;
var Mul := function(A, B: Int32): Int32; => Exit(A * B);
async function TWorker.Square(const N: Int32): Int32; // RTL do compilador
A := Worker.Square(6); R := await A; R1, R2 := await C, D;Nulos, memória e eventos#
Age: ?Int32; Age := Null; Age ?? -1; Age!; ?Age; X?.Idade; ?X ? X.Idade : 0
weak FParent: TNode;
FAddress: Ref(TAddress, FCustomer); FItems: Refs(TItem, FOwner);
FParcels: ChainRoot(TParcel, FChainInInvoice); FChainInInvoice: Chain;
for P in FParcels do …; for P downin FParcels do …;
weak FOnClick: Delegate(TNotifyEvent); FOnClick!(Self);
AtomicIncrement(Counter); AtomicCmpExchange(Counter, New, Expected);
X: UInt64 absolute P;Compilação#
{$define TRACE} {$ifdef TRACE} … {$endif} {$if Is(T, UInt8)} … {$elseif IsString(T)} … {$endif}
{$include Unit1.designer.fxi} {$message hint 'texto'} {$config AppType GUI} {$code unsafe}
{$macro Nome(P) function %P%; … end;}
late module X; meta module Y; inject into procedure Foo segment 0; begin … end inject;
attribute DbTable(const Name: LString); [DbTable('CUSTOMERS')]Linha de comando#
fc Meu.fxp # tudo padrão (-O3)
fc Meu.fxp -O0 -g -o Meu.exe # desenvolvimento, com depuração
fc Meu.fxp -PMSWin64 -MRelease # plataforma e modo
fc Meu.fxp --NoPackages # a RTL inteira dentro do binário