Sign in Join

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

Mailing lists / fpc-devel / 2005-02

Abbrevia and Delphi compatibility

14 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

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

DrDiettrich

After eliminating dozens of bugs now I have a working version of Abbrevia for Delphi. Unfortunately this version is not usable with FPC, primarily because FPC doesn't support properties for the Object type.

In my code I like to use Object for records with methods and properties, which need no dynamic memory allocation. In Abbrevia this feature allowed to eliminate near 100 methods of various classes, and simplified more code. After all I found the following essential features missing in FPC:

1) Properties for Object type.
2) Sets with minimal size, at least with 1 and 2 bytes for replacement of Byte and Word types.

I consider both features as vital in translations from C to Pascal, and in the detection and elimination of bugs. Will it be possible to add these features to FPC, this year?

DoDi

Reply by email

Jonas Maebe
to DrDiettrich
DrDiettrich wrote
1) Properties for Object type.

I guess this won't be that hard to add, given that we already support global properties (so they're not really tied to classes)

2) Sets with minimal size, at least with 1 and 2 bytes for replacement of Byte and Word types.

This would be quite a bit more work.

Jonas

Reply by email

Peter Vreman
to DrDiettrich: After eliminating dozens of bugs now I have a working version of Abbrevia for Delphi.…
Show quoted text 11 lines
After eliminating dozens of bugs now I have a working version of Abbrevia for Delphi. Unfortunately this version is not usable with FPC, primarily because FPC doesn't support properties for the Object type. In my code I like to use Object for records with methods and properties, which need no dynamic memory allocation. In Abbrevia this feature allowed to eliminate near 100 methods of various classes, and simplified more code. After all I found the following essential features missing in FPC: 1) Properties for Object type.

Since which Delphi version is a property allowed in an normal object? Currently FPC has special code that forbids property in objects for delphi mode.

Show quoted text 6 lines
2) Sets with minimal size, at least with 1 and 2 bytes for replacement of Byte and Word types. I consider both features as vital in translations from C to Pascal, and in the detection and elimination of bugs. Will it be possible to add these features to FPC, this year?

We can't promise anything.

Reply by email

Peter Vreman
to DrDiettrich: After eliminating dozens of bugs now I have a working version of Abbrevia for Delphi.…
Show quoted text 11 lines
After eliminating dozens of bugs now I have a working version of Abbrevia for Delphi. Unfortunately this version is not usable with FPC, primarily because FPC doesn't support properties for the Object type. In my code I like to use Object for records with methods and properties, which need no dynamic memory allocation. In Abbrevia this feature allowed to eliminate near 100 methods of various classes, and simplified more code. After all I found the following essential features missing in FPC: 1) Properties for Object type.

Since which Delphi version is this allowed? FPC has an explicit check for delphi mode to disable property in tp style object.

Reply by email

Peter Vreman
to DrDiettrich: After eliminating dozens of bugs now I have a working version of Abbrevia for Delphi.…
Show quoted text 11 lines
After eliminating dozens of bugs now I have a working version of Abbrevia for Delphi. Unfortunately this version is not usable with FPC, primarily because FPC doesn't support properties for the Object type. In my code I like to use Object for records with methods and properties, which need no dynamic memory allocation. In Abbrevia this feature allowed to eliminate near 100 methods of various classes, and simplified more code. After all I found the following essential features missing in FPC: 1) Properties for Object type.

Since which Delphi version is this allowed? FPC has an explicit check for delphi mode to disable property in tp style object.

Reply by email

Marco van de Voort
to Peter Vreman
Show quoted text 14 lines
> After eliminating dozens of bugs now I have a working version of > Abbrevia for Delphi. Unfortunately this version is not usable with FPC, > primarily because FPC doesn't support properties for the Object type. > > In my code I like to use Object for records with methods and properties, > which need no dynamic memory allocation. In Abbrevia this feature > allowed to eliminate near 100 methods of various classes, and simplified > more code. After all I found the following essential features missing in > FPC: > > 1) Properties for Object type. Since which Delphi version is this allowed? FPC has an explicit check for delphi mode to disable property in tp style object.

D6 accepts:

  type x = object
             fblaat : integer;
             property blaat:integer read fblaat write fblaat;
             end;

assignig fblaat and writeln(blaat) also works.

So it seems it works as expected in D6.

Reply by email

Marco van de Voort
to DrDiettrich: After eliminating dozens of bugs now I have a working version of Abbrevia for Delphi.…
Show quoted text 6 lines
2) Sets with minimal size, at least with 1 and 2 bytes for replacement of Byte and Word types. I consider both features as vital in translations from C to Pascal, and in the detection and elimination of bugs. Will it be possible to add these features to FPC, this year?

I'm interested in the last one. What is exactly the problem with it, except foreign data, like API declarations (which are rare anyway), and binary files?

The C argument is a bit doubtful, since there are more such problems (like bitpacking, not being able to exactly duplicate any union), so 1:1 remapping is not really possible anyway.

Reply by email

Pavel V. Ozerski
to Marco van de Voort: D6 accepts: type x = object fblaat : integer; property blaat:integer read fblaat write…

Hello Marco,

you wrote
Currently FPC has special code that forbids property in objects for delphi mode.

At least Delphi versions from 2 to 7 support propereties for old-style objects. This feature is used BTW in KOL library. Some years ago I implemented a patch for FPC 1.1 which resolved this feature for Delphi compatible mode but suppressed for all others. I hope that this feature is not removed also now (but I have not latest FPC builds now).

Reply by email

Alexey Barkovoy
to Marco van de Voort: I'm interested in the last one. What is exactly the problem with it, except foreign data,…
> 2) Sets with minimal size, at least with 1 and 2 bytes for replacement > of Byte and Word types.

This is already correctly working (at least in FPC 1.9.x). For example:

type
{$MINENUMSIZE 2}
enumDMUS_VARIATIONT_TYPES = (
DMUS_VARIATIONT_SEQUENTIAL {= 0}, (* Play sequential starting with variation 1. *)
DMUS_VARIATIONT_RANDOM {= 1}, (* Play randomly. *) DMUS_VARIATIONT_RANDOM_START {= 2}, (* Play sequential starting with a random variation. *)
DMUS_VARIATIONT_NO_REPEAT {= 3}, (* Play randomly, but don't play the same variation twice. *)
DMUS_VARIATIONT_RANDOM_ROW {= 4} (* Play randomly as a row: don't repeat any variation until all have played. *)

  );
begin
  WriteLn(SizeOf(enumDMUS_VARIATIONT_TYPES));
end.

will write "2"

Reply by email

Marco van de Voort
to Marco van de Voort: D6 accepts: type x = object fblaat : integer; property blaat:integer read fblaat write…
Show quoted text 10 lines
D6 accepts: type x = object fblaat : integer; property blaat:integer read fblaat write fblaat; end; assignig fblaat and writeln(blaat) also works. So it seems it works as expected in D6.

Same with FPC, the below program prints 1234 (recent 1.9.7):

{$mode delphi}
 type x = object
             fblaat : integer;
	     procedure fillblaat;
             property blaat:integer read fblaat write fblaat;
             end;
procedure x.fillblaat;
begin
  fblaat:=1234;	// this 1234 is printed.
end;
var y:x;
begin
  y.fblaat:=1234;
  y.fillblaat;	       	// this can be omitted and it still works
  writeln(y.blaat);
end.

Reply by email

DrDiettrich
to Peter Vreman: Since which Delphi version is a property allowed in an normal object? Currently FPC has…
Peter Vreman wrote
> 1) Properties for Object type. Since which Delphi version is a property allowed in an normal object?

I'm not sure, but at least D4 supports such properties.

Currently FPC has special code that forbids property in objects for delphi mode.

Then it would be sufficient to remove that special code?

BTW, I didn't find object properties mentioned in the FPC documentation (HTML). Properties only are described for Class types?

We can't promise anything.

Granted ;-)

DoDi

Reply by email

DrDiettrich
to Marco van de Voort: I'm interested in the last one. What is exactly the problem with it, except foreign data,…
Marco van de Voort wrote 11 lines
> 2) Sets with minimal size, at least with 1 and 2 bytes for replacement > of Byte and Word types. > > I consider both features as vital in translations from C to Pascal, and > in the detection and elimination of bugs. Will it be possible to add > these features to FPC, this year? I'm interested in the last one. What is exactly the problem with it, except foreign data, like API declarations (which are rare anyway), and binary files?

The size restriction applies almost only to filed records, whereas in-memory data structures usually can be use of enums and sets allows for safer code, instead of working with bitmasks and general ordinal data types and constants. According (set) variables can be found in many data structures, so that it would be nice to retype such fields as appropriate sets in Pascal code.

The C argument is a bit doubtful, since there are more such problems (like bitpacking, not being able to exactly duplicate any union), so 1:1 remapping is not really possible anyway.

Even C bitfields can be emulated perfectly in Pascal, with Object types and properties.
Named C unions can be emulated by variant records in Pascal, only anonymous unions sometimes require changes to the code, or the use of objects with properties. But also some (legacy) Pascal constructs (file open mode...) could be much nicer and safer with structured data types.

DoDi

Reply by email