Hosted By:
Lunarpages.com Web Hosting
Choose Language:
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
                    //{ Private declarations }
                  public
                    //{ Public declarations }
                  end;

                var
                  Form1: TForm1;
                implementation

                  procedure TForm1.Button1Click(Sender: TObject);
                  begin
                    //Dosmoething
                  end;
				  
                  begin
                      TForm1.ButtonClick(TObject);  
                  end.                   
            
Comments
                { Text between a left brace and a right brace constitutes a comment. }
                
                (* Text between a left-parenthesis-plus-asterisk and an 
                asterisk-plus-right-parenthesis also constitutes a comment. *)
                
                // Any text between a double-slash and the end of the line constitutes a comment.
			
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;
				
                //Dynamic arrays
                var MyFlexibleArray: array of Real;
                SetLength(MyFlexibleArray, 20);
				
                type TMessageGrid = array of array of string;
                SetLength(Msgs,I,J);
            
Operators
                
                //Arithmetic
                * / + - mod div
                
                //Logical
                not and or xor
                
                //Bitwise
                not and or xor shl shr
                
                //Assignment
                :=
                
                //Comparison
                < <= > >= = <>      

                //Pointer
                ^              
            
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
                //Declarations and statements are organized into blocks,
                //which define local namespaces (or scopes) for labels and identifiers.
                //Blocks allow a single identifier, such as a variable name,
                //to have different meanings in different parts of a program.
                //Each block is part of the declaration of a program, function, or procedure;
                //each program, function, or procedure declaration has one block.
                
            
Classes & Structs
                //Accessibility
                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;   
				             
                //Record
                type
                    TDateRec = record
                        Year: Integer;
                        Month: (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
                        Day: 1..31;
                    end;  
                //You can access the fields of a record by qualifying the field 
                //designators with the records name:
                
                var Record1 : TDateRec;      
                Record1.Year := 1904;
                Record1.Month := Jun;
                Record1.Day := 16;

                //Or use a with statement:
                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
                //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;  //Max is a returning value
                    end;

                //Procedures
                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
                //Raising an exception                    
                if Password <> CorrectPassword then 
                    raise EPasswordInvalid.Create('Incorrect password entered');
				
                function GetAverage(Sum, NumberOfItems: Integer): Integer;
                begin
                  try
                    Result := Sum div NumberOfItems;	//{ handle the normal case }
                  except
                    on EDivByZero do Result := 0;	//{ handle the exception only if needed }
                  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;
                    //Constructors                      
                  constructor TShape.Create(Owner: TComponent);
                  begin
                    inherited Create(Owner);  // Initialize inherited parts
                    Width := 65;  // Change inherited properties
                    Height := 65;
                    FPen := TPen.Create;  // Initialize new fields
                    FPen.OnChange := PenChanged;
                    FBrush := TBrush.Create;
                    FBrush.OnChange := BrushChanged;
                  end;
                   //Destructor 					  
                  destructor TShape.Destroy;
                  begin
                    FBrush.Free;
                    FPen.Free;
                    inherited Destroy;
                  end;
            
Properties
                type
                  TYourComponent = class(TComponent)
                  private
                    FCount: Integer;                        //{ used for internal storage }
                    procedure SetCount (Value: Integer);    //{ write method }
                  public
                    property Count: Integer read FCount write SetCount;
                  end;              
            
Delegates
                property RGB8Intf: IRGB8bit read FRGB8bit implements IRGB8bit;