Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2001-03

Delphi incompatibity

3 messages · 1 person · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Pavel V. Ozerski

Hello,
I try to recompile KOL with Free Pascal.
First big problem: FPC does not support properties in "BP-style" objects, unlike Delphi 3! Kol source code contains things like this really existing sample:

  TStream = object(TObj)
  {* Simple stream object. Can be opened for file, or as memory stream (see
     NewReadFileStream, NewWriteFileStream, NewMemoryStream). }
  private
    fMethods: TStreamMethods;
    fMemory: Pointer;
    fData: TStreamData;
  protected
    procedure SetPosition(Value: DWord);
    function GetPosition: DWord;
    function GetSize: DWord;
    procedure SetSize(NewSize: DWord);
    destructor Destroy; virtual;
  public
    function Read(var Buffer; Count: DWord): DWord;
    function Seek(MoveTo: Integer; MoveMethod: TMoveMethod): DWord;
    function Write(var Buffer; Count: DWord): DWord;
    property Size: DWord read GetSize write SetSize;
    property Position: DWord read GetPosition write SetPosition;
    property Memory: Pointer read fMemory; // only for memory stream
  end;

Pavel

Reply by email

Pavel V. Ozerski
to Pavel V. Ozerski

Hello,
1) I tried to switch on properties in BP-style objects. My first attempt is very rough: I disabled in procedure property_dec (pdecobj.pas) initial checking for a class. But my example not only can be compiled but also runs and gives correct result!

{$APPTYPE CONSOLE}
{$MODE OBJFPC}
type
 Tobj1=object
  private
   xx:longint;
  protected
    procedure SetX(Value:longint);
    procedure Init;virtual;
  public
    constructor Create;
    property X: longint read xx write SetX;
  end;
procedure TObj1.SetX(Value:longint);
 begin
  xx:=Value;
 end;
constructor TObj1.Create;
 begin
  Init;
 end;
procedure TObj1.Init;
 begin
  FillChar( Pointer( Integer( @Self ) + 8 )^, Sizeof( Self ) - 8, 0 );
//  Self.fRefCount := 0;
 end;
var
 Obj1:Tobj1;
begin
 Obj1.Create;
 Obj1.x:=1;
 writeln(Obj1.x);
end.

2) While my experiments I found a bug in Windows unit (really, in func.inc). This unit contains a reference to function EnumTaskWindows as located in USER32.dll. But at least in NT 4 user32.dll does not contain this function. In Delphi 3 RTL this function is implemented as

function EnumTaskWindows(hTask: THandle; lpfn: FARPROC; lParam: LPARAM): BOOL;
begin
  Result := EnumThreadWindows(DWORD(hTask), lpfn, lParam);
end;

I think, for Win32 better (and faster) would be

function EnumTaskWindows(hTask:HWND; lpfn:FARPROC; lParam: LPARAM): BOOL;stdcall;
 external 'user32' name 'EnumThreadWindows';

because in Win32 Thandle and DWORD are 4-byte integers.

Pavel

Reply by email

Pavel V. Ozerski
to Pavel V. Ozerski

Hello,

There are new new problems with properties which I found by porting KOL:

1) if property has index, it cannot access to class fields by reading/writing, unlike Delphi. Sample which can be compiled by Delphi but not by FPC:

{$APPTYPE CONSOLE}
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
type
aClass=class
 private
  aa:longint;
  procedure bb(index:integer;value:longint);
 public
  property cc:longint index 1 read aa write bb;
end;
procedure AClass.bb(index:integer;value:longint);
 begin
  aa:=value;
 end;
var
 C:aClass;
begin
 C:=aClass.Create;
 C.cc:=1;
 writeln(C.cc);
end.

To use it with FPC, I must write a method - function with dummy index parameter! It is a solution but it is not good!

2) index in properties in FPC cannot be outside of LONGINT range (even if it is inside CARDINAL range);
 property AAA:longint index $FFFFFFFF read ... is good for Delphi but causes error message in FPC.

Pavel

Reply by email