Recent

Author Topic: Porting a Delphi Project  (Read 20798 times)

simone

  • Hero Member
  • *****
  • Posts: 573
Porting a Delphi Project
« on: August 26, 2016, 11:33:02 am »
I'm trying to port a simple Delphi 5 project (it's a parser generator) to Lazarus (http://www.goldparser.org/engine/1/delphi/rai/rai-delphi-source-d5.zip).

I used the conversion utility of Lazarus, that performs the task without errors, but during the compilation phase, I have following errors:

GrammarReader.pas(106,10) Error: Identifier not found "VarClear"
GrammarReader.pas(107,28) Error: Identifier not found "VarArrayCreate"

It seems to me that VarClear procedure and VarArrayCreate function, bot relating to variants in System unit of Delphi, are actually not implemented in Freepascal. Indeed I'm not able to find them in RTL documentation.

Anyone has suggestion for this problem? Thanks in advice!
« Last Edit: August 26, 2016, 07:29:43 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: Porting a Delphi Project
« Reply #1 on: August 26, 2016, 11:35:14 am »
I think that Delphi moved variant functions to unit "variants" beginning with version 6. --> Try to add "variants" to uses.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Porting a Delphi Project
« Reply #2 on: August 26, 2016, 11:41:23 am »
I think that Delphi moved variant functions to unit "variants" beginning with version 6. --> Try to add "variants" to uses.
That's 100% correct. Add variants.
BTW if you use the gold parser sources for D7 it compiles out of the box in mode Delphi. (Not the GUI, that needs the converter fromLazarus tools.)
« Last Edit: August 26, 2016, 11:43:00 am by Thaddy »
Specialize a type, not a var.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Porting a Delphi Project
« Reply #3 on: August 26, 2016, 11:52:50 am »
Oops. I did that one myself  :o :'( O:-)
I'll see if I can find the sources.
[edit]
I did, but it only adds variants and solves some issues that the compiler warns or errors on. Easy enough.

[edit2]
Btw: a parser generator is not "simple"! by definition. It is on the contrary a pretty complex application geared towards compiler engineers.
Not something the average user would consider "simple". It isn't. Then you would have found out the dependency yourself ;)
« Last Edit: August 26, 2016, 12:09:10 pm by Thaddy »
Specialize a type, not a var.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Porting a Delphi Project
« Reply #4 on: August 26, 2016, 12:48:04 pm »
The attachment contains a fully cross-platform version of the gold parser for Freepascal/Lazarus AND delphi.
To use under freepascal you just have to convert the main form.
I also cleaned up the code. (that s*cked with stupid dependencies) and removed all warnings.

Atm I don't have a Laz install, so maybe someone else can do a quick port for the dpr application and mainform units (see comments inside the dpr, it 's documented what to do)

Everything else is now cross platform FPC/Laz not just windows.

You can submit it to the official website as long as the original author Martin van der Geer, Thaddy de Koning (fpc) and you are mentioned as the authors or "based on"
This is the version used, because it is the most stable one: http://goldparser.org/engine/1/delphi/van-der-geer/van-der-geer-delphi-src-v0.2.zip
« Last Edit: August 26, 2016, 12:55:00 pm by Thaddy »
Specialize a type, not a var.

simone

  • Hero Member
  • *****
  • Posts: 573
Re: Porting a Delphi Project
« Reply #5 on: August 26, 2016, 01:09:17 pm »
Adding the variant unit to uses, compilation terminates without problem
and the program seems to work properly. Thank you!

Another trivial question... The converter derives a .lfm file from orginal .dfm file.,
but, in spite of this, Object Inspector and Form Editor do not show objects of the GUI.

Why this happens? Thanks again!
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Porting a Delphi Project
« Reply #6 on: August 26, 2016, 01:35:53 pm »
Adding the variant unit to uses, compilation terminates without problem
and the program seems to work properly. Thank you!

Another trivial question... The converter derives a .lfm file from orginal .dfm file.,
but, in spite of this, Object Inspector and Form Editor do not show objects of the GUI.

Why this happens? Thanks again!

They are not components, but classes. Classes need some extra registration code and rtti to show up in the ide.
That is not the case in the original code, but can be achieved by adding {$M+} to any of the units that has a published section.
That is - apart from the form - only the case for GoldParserCmp.pas, so should be easy to solve. Just add {$M+} on top, but after the fpc define, of that unit.

Btw: my version of the code works also on Linux arm. Actually I did the port on a Raspberry Pi 3. ;)
« Last Edit: August 26, 2016, 01:37:46 pm by Thaddy »
Specialize a type, not a var.

balazsszekely

  • Guest
Re: Porting a Delphi Project
« Reply #7 on: August 26, 2016, 01:37:21 pm »
Quote
@simone
Another trivial question... The converter derives a .lfm file from orginal .dfm file.,
but, in spite of this, Object Inspector and Form Editor do not show objects of the GUI.
There is a single form in the project, namely: Main(unit MainForm) and it can be opened without any problems.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Porting a Delphi Project
« Reply #8 on: August 26, 2016, 01:39:54 pm »
@Getmem: then apart from the {$M+} in GoldParserCmp.pas in my new code everything should work x-platform even. I just tested a quick commandline app to make sure the code was OK.
Specialize a type, not a var.

simone

  • Hero Member
  • *****
  • Posts: 573
Re: Porting a Delphi Project
« Reply #9 on: August 26, 2016, 01:46:16 pm »
Thanks to all! Dear Thaddy, I'm a senior computer engineer (may be, too old...), but I leaved Turbo Pascal twenty years ago... Now I begin
again, and so i think to me as a beginner... I apologize...

Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Porting a Delphi Project
« Reply #10 on: August 26, 2016, 02:11:02 pm »
Thanks to all! Dear Thaddy, I'm a senior computer engineer (may be, too old...), but I leaved Turbo Pascal twenty years ago... Now I begin
again, and so i think to me as a beginner... I apologize...
;) It was not my intention to offend you. I hope my code helps. Gold Parser is a favorite of mine, that's why I translated it before to D7 and now made it cross platform with little effort.... :)
I knew you are a well educated programmer just because you use parser generators. Even on this forum there aren't that many that can even use a parser generator for something simple like json.
If you felt offended, accept my apologies. I have a sharp pen.
Specialize a type, not a var.

simone

  • Hero Member
  • *****
  • Posts: 573
Re: Porting a Delphi Project
« Reply #11 on: August 26, 2016, 02:19:41 pm »
No! I'm not offended! On the contrary, you are very kind with me!!!
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

simone

  • Hero Member
  • *****
  • Posts: 573
Re: Porting a Delphi Project
« Reply #12 on: August 26, 2016, 05:22:02 pm »
Only an addendum: although not famous as LEX & YACC, FLEX & BISON or ANTLR, GOLD (http://www.goldparser.org/) is a good parser generator and, feature very important for our community, the only that supports object pascal as output language (as far as I know).

Moreover in the above website is available a formal grammar (in BNF form) for object-pascal. It should be adapted to embrace the latest language evolutions of FreePascal, in FPC 3.0.0 particolar, but is a good start point. It should not be too difficult to update the formal grammar provided by GOLD website using syntax diagram depicted in the language user guide of FPC.

I do not know if someone else has already write a BNF / EBNF for FreePascal. Indeed it seems to me that the compiler FPC uses an ad hoc parser, not one automatically built by a generator (for efficiency reasons, I presume).
« Last Edit: August 26, 2016, 05:54:24 pm by simone »
Microsoft Windows 10 64 bit - Lazarus 3.0 FPC 3.2.2 x86_64-win64-win32/win64

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Porting a Delphi Project
« Reply #13 on: August 26, 2016, 06:06:00 pm »
Only an addendum: although not famous as LEX & YACC, FLEX & BISON or ANTLR, GOLD (http://www.goldparser.org/) is a good parser generator and, feature very important for our community, the only that supports object pascal as output language (as far as I know).

Search for Coco/r, also a pascal producing yacc/lex is part of the FPC distribution.

 

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: Porting a Delphi Project
« Reply #14 on: August 26, 2016, 06:25:22 pm »
Only an addendum: although not famous as LEX & YACC, FLEX & BISON or ANTLR, GOLD (http://www.goldparser.org/) is a good parser generator and, feature very important for our community, the only that supports object pascal as output language (as far as I know).

Search for Coco/r, also a pascal producing yacc/lex is part of the FPC distribution.
I was never able or willing to translate coco/r in higher Delphi versions. I still use the default yacc/lex, but the Gold parser has particulary clean code and is easy to use.
That's why it is a favorite of mine. It has also many example grammars and full grammars. More than coco/r

[edit]
OTOH I am glad to see dcoco/r is actively maintained https://github.com/VilleKrumlinde/dcocor
There are more delphi versions but with this one I used to be somewhat familiar and, well, at that moment in my opinion a really good one.
I still prefer the Gold parser though, thats a matter of taste I guess.
« Last Edit: August 26, 2016, 07:06:33 pm by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018