| Program Structure |
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
procedure TForm1.Button1Click(Sender: TObject);
begin
end;
begin
TForm1.ButtonClick(TObject);
end.
|
| Comments |
| Data Types |
integer
character
Boolean
enumerated
subrange
real
string
set
array
record
file
class
class reference
interface
|
| Arrays |
var MyArray: array[1..100] of Char;
type TMatrix = array[1..10] of array[1..50] of Real;int [][] a1 = new int[2][3];
type TMatrix = array[1..10, 1..50] of Real;
I:Integer;
Max:Integer;
Max:=59;
for I := 1 to 100 do
if MyArray[I] > Max the
Max := Data[I];
packed array[Boolean,1..10,TShoeSize] of Integer;
packed array[Boolean] of packed array[1..10] of packed array[TShoeSize] of Integer;
var MyFlexibleArray: array of Real;
SetLength(MyFlexibleArray, 20);
type TMessageGrid = array of array of string;
SetLength(Msgs,I,J);
|
| Operators |
* / + - mod div
not and or xor
not and or xor shl shr
:=
< <= > >= = <>
^
|
| Decisions |
if J <> 0 then
begin
Result := I/J;
Count := Count + 1;
end
else if Count = Last then
Done := True
else
Exit;
case MyColor of
Red: X := 1;
Green: X := 2;
Blue: X := 3;
Yellow, Orange, Black: X := 0;
end;
|
| Loops |
repeat
Write('Enter a value (0..9): ');
Readln(I);
until (I >= 0) and (I <= 9);
while I > 0 do
begin
if Odd(I) then Z := Z * X;
I := I div 2;
X := Sqr(X);
end;
for I := 2 to 63 do
if Data[I] > Max then
Max := Data[I];
|
| Casting & Conversion |
Label1.Caption := IntToStr(StrToInt(Edit1.Text) * StrToInt(Edit2.Text));
I:Integer;
I := StrToInt(Edit1.Text);
|
| Enumeration |
type TSound = (Click, Clack, Clock);
procedure TForm1.DBGrid1Enter(Sender: TObject);
var Thing: TSound;
begin
Thing := Click;
end;
var MyCard: (Club, Diamond, Heart, Spade);
|
| Namespaces |
|
| Classes & Structs |
private
protected
public
published
type
TMemoryStream = class(TCustomMemoryStream)
private
FCapacity: Longint;
protected
property Capacity: Longint read FCapacity write SetCapacity;
public
destructor Destroy; override;
procedure Clear;
inherited function Write(const Buffer; Count: Longint): Longint; override;
end;
type
TDateRec = record
Year: Integer;
Month: (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
Day: 1..31;
end;
var Record1 : TDateRec;
Record1.Year := 1904;
Record1.Month := Jun;
Record1.Day := 16;
with Record1 do
begin
Year := 1904;
Month := Jun;
Day := 16;
end;
|
| Interfaces |
type
IMalloc = interface(IInterface)
['{00000002-0000-0000-C000-000000000046}']
function Alloc(Size: Integer): Pointer; stdcall;
function Realloc(P: Pointer; Size: Integer): Pointer; stdcall;
procedure Free(P: Pointer); stdcall;
function GetSize(P: Pointer): Integer; stdcall;
function DidAlloc(P: Pointer): Integer; stdcall;
procedure HeapMinimize; stdcall;
end;
|
| Functions |
function Max(A: array of Real; N: Integer): Real;
var
X: Real;
I: Integer;
begin
X := A[0];
for I := 1 to N - 1 do
if X < A[I] then X := A[I];
Max := X;
end;
procedure NumString(N: Integer; var S: string);
var
V: Integer;
begin
V := Abs(N);
S := '';
repeat
S := Chr(V mod 10 + Ord('0')) + S;
V := V div 10;
until V = 0;
if N < 0 then S := '-' + S;
end;
|
| Exception Handling |
if Password <> CorrectPassword then
raise EPasswordInvalid.Create('Incorrect password entered');
function GetAverage(Sum, NumberOfItems: Integer): Integer;
begin
try
Result := Sum div NumberOfItems;
except
on EDivByZero do Result := 0;
end;
end;
|
| Constructors/Desctructors |
type
TShape = class(TGraphicControl)
private
FPen: TPen;
FBrush: TBrush;
procedure PenChanged(Sender: TObject);
procedure BrushChanged(Sender: TObject);
public
constructor Create(Owner: TComponent); override;
destructor Destroy; override;
end;
constructor TShape.Create(Owner: TComponent);
begin
inherited Create(Owner);
Width := 65;
Height := 65;
FPen := TPen.Create;
FPen.OnChange := PenChanged;
FBrush := TBrush.Create;
FBrush.OnChange := BrushChanged;
end;
destructor TShape.Destroy;
begin
FBrush.Free;
FPen.Free;
inherited Destroy;
end;
|
| Properties |
type
TYourComponent = class(TComponent)
private
FCount: Integer;
procedure SetCount (Value: Integer);
public
property Count: Integer read FCount write SetCount;
end;
|
| Delegates |
property RGB8Intf: IRGB8bit read FRGB8bit implements IRGB8bit;
|