Deprecated: Assigning the return value of new by reference is deprecated in /var/www/virtual/geshi.org/htdocs/wiki/inc/parser/xhtml.php on line 943
Table of Contents

Delphi

The Delphi Language (former Object Pascal) is a quite old, but nice to read language for developement of (mainly) non-scientific applications. Delphi’s basic advantages are fast compilation with quite fast binaries. Its strength are database applications especially and the availability of a lot of components for extension. Graphic programming is very well possible, but due to some compiler limitations not always the fastest. Still, there are many mostly non-commercial graphical applications written with Delphi. Delphi itself is not crossplattform compatible unless you use the CLX library or write your source compatible for FreePascal/Lazarus or Kylix.

Author

The current version of this language file has been created by Benny Baumann BenBE@benbe.omorphia.de, who found the old language file for 1.0.X branch a bit to minimalistic (and sometimes even quite wrong). The current effords on extending the language file aim on highlighting the semantic of the language rather than just colorizing the source. Thus you’ll notice alot of things to be highlighted that are not even highlighted by Pascal IDEs like Delphi or FreePascal.

I’m leader of a 3D Graphics engine project (called Omorphia) which is open source too and aims on the creation of a basic and referencial engine to create multimedia graphics and game applications.

State

The current state of the language files gives a quite realistic view of the source although there are still some known bugs that are caused by (up to the current state) missing parser features.

The current color theme should be considered experimental and for debugging usage. Once Theming Support has been implemented the standard Delphi IDE Theme, the Theme like in the German Delphi-Forum and maybe for some other well-known pages may follow.

Until that this (my personal, advanced behind Delphi Theme) will stay the default :P

Features

The Delphi support file has at the moment the following features:

  1. Support for highlighting the basic syntax
  2. Highlighting of some constructions with context dependent keywords (e.g. read and write in property declarations)
  3. Highlighting of most standard functions of the CLX/VCL that are implemented in units System, SysUtils, StrUtils, Maths and Classes.
  4. Advanced Support for highlighting inline assembler (nearly highlights the actual syntax)

If I missed anything else someone would consider being a “feature” I’d appreciate knowing about that ;-)

Examples

The current version of GeSHi can do the basic syntax highlighting, which will (in most cases) suit highlighting a HelloWorld program

program Hello;

begin
    WriteLn('Hello World!');
end.

as well as highlighting more complex sources:

unit Unit1;

//This is an unit for testing basic features ...

interface

{This is a

multiline comment}

(*that gets followed by a compiler directive*)
{$R+}

uses
    Windows;

procedure Hello;

implementation

procedure Hello;
begin
    WriteLn('Hello World!');
end;

initialization
    Hello;
finalization
    Halt(0);
end.

As you might notice this doesn’t satisfy the developement of such a complex parser ...

The current engine provides many features that lets even uncommon source look like (or even better) than inside your Delphi IDE.

Examples for such uncommon, or quite problematic sources are

procedure Register;
begin
    RegisterComponents('GeSHi', [TGeSHiComponent]);
end;

procedure ABC(A: Integer; Register: Integer); Register;
begin
    Foo;
    Bar;
end;

Other improvements go towards the default and the message modifiers that are rarely used inside Delphi but have to be handled extra too:

type
    TMyComponent = class(TComponent)
    private
        procedure WMClick(var Message: TMessage); message WM_CLICK;
        function GetA(Index: Integer): String;
    public
        property A[Index: Integer]: String read GetA; default;
    end;

procedure TMyComponent.WMClick(var Message: TMessage);
begin
    If Message.wParam = 0 Then
        Exit;
    message.lParam := StrToInt('1');
end;

function TMyComponent.GetA(Index: Integer): String;
begin
    Result := IntToStr(A);
end;

Another thing that has been included in this new release of the language file was support for embedded inline asm.

Function IsBitSet(Const BitSet: DWORD; Const Bit: Byte): Boolean;
//    Result := BitSet And (1 Shl Bit) <> 0;
Asm
    MOVZX   EDX, DL
    BT      EAX, EDX
    SETC    AL
End;

The supported instructions currently cover all instructions of 8086 up to Pentium 4 for AMD and Intel as well as MMX, SSE and 3Dnow!, although the latter 3 might still include some mistakes.

Another improvement that will be done shortly will be highlighting of some special ASM constructions like those seen below:

procedure Hello;
asm
    MOV EAX, $4711 XOR $666
    AND EAX, $0815 AND $1337
end;

The special thing about those lines is that the XOR and AND instructions in the second parameter are not ASM instructions, but Operators for Delphi thus they should be highlighted as such ;-) This will be done in a few days.

Another thing, that already has been included, is highlighting of registers in ASM as such making sources with Registers and Identifiers more readable due to more structure:

Function IsValidHandle(Const Handle: THandle): Boolean; {$IFDEF OMORPHIA_FEATURES_USEASM} Assembler;
Asm
    TEST    EAX, EAX
    JZ      @@Finish
    NOT     EAX
    TEST    EAX, EAX
    SETNZ   AL

    {$IFDEF WINDOWS}
    JZ      @@Finish

    //Save the handle against modifications or loss
    PUSH    EAX

    //reserve some space for a later duplicate
    PUSH    EAX

    //Check if we are working on NT-Platform
    CALL    IsWindowsNTSystem
    TEST    EAX, EAX
    JZ      @@NoNTSystem

    PUSH    DWORD PTR [ESP]
    LEA     EAX, DWORD PTR [ESP+$04]
    PUSH    EAX
    CALL    GetHandleInformation
    TEST    EAX, EAX
    JNZ     @@Finish2

@@NoNTSystem:
    //Result := DuplicateHandle(GetCurrentProcess, Handle, GetCurrentProcess,
    //  @Duplicate, 0, False, DUPLICATE_SAME_ACCESS);
    PUSH    DUPLICATE_SAME_ACCESS
    PUSH    $00000000
    PUSH    $00000000
    LEA     EAX, DWORD PTR [ESP+$0C]
    PUSH    EAX
    CALL    GetCurrentProcess
    PUSH    EAX
    PUSH    DWORD PTR [ESP+$18]
    PUSH    EAX
    CALL    DuplicateHandle

    TEST    EAX, EAX
    JZ      @@Finish2

    //  Result := CloseHandle(Duplicate);
    PUSH    DWORD PTR [ESP]
    CALL    CloseHandle

@@Finish2:
    POP     EDX
    POP     EDX

    PUSH    EAX
    PUSH    $00000000
    CALL    SetLastError
    POP     EAX
    {$ENDIF}

@@Finish:
End;
{$ELSE}
Var
    Duplicate: THandle;
    Flags: DWORD;
Begin
    If IsWinNT Then
        Result := GetHandleInformation(Handle, Flags)
    Else
        Result := False;
    If Not Result Then
    Begin
        // DuplicateHandle is used as an additional check for those object types not
        // supported by GetHandleInformation (e.g. according to the documentation,
        // GetHandleInformation doesn't support window stations and desktop although
        // tests show that it does). GetHandleInformation is tried first because its
        // much faster. Additionally GetHandleInformation is only supported on NT...
        Result := DuplicateHandle(GetCurrentProcess, Handle, GetCurrentProcess,
            @Duplicate, 0, False, DUPLICATE_SAME_ACCESS);
        If Result Then
            Result := CloseHandle(Duplicate);
    End;
End;
{$ENDIF}

Another feature of the current source code parser is a simple, but quite effective internal block detection to avoid mishighlighting of e.g. the message modifier when inside a procedure or highlighting the default keyword in places where it shouldn’t. The current language file therefore has been extended to implement support for even rare constructs covering a broad range of (even uncommon) Delphi sources.

Known bugs

Please refer to the bugtracker for information on known issues.

 
lang/delphi.txt · Last modified: 2011/09/01 13:03
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki