Recent

Author Topic: Projects written in old Free Pascal  (Read 1941 times)

rigczTheSky

  • Newbie
  • Posts: 5
Projects written in old Free Pascal
« on: November 27, 2023, 01:41:48 pm »
Hello everyone. A few months ago i've got a new job. When i started, i found out that i have to work on Lazarus v 0.9.22. It is like that because my project was primarly written on Turbo Pascal. Next was moved on Lazarus propably someday in 2007. As my collegue said, there was a huge change in Lazarus development propably between version 0.9.22 and 0.9.24 and when new version was released it wasn't possible to compile our code on that. My team tried to rewrite project but the further they goes, the more complicated things became. I heard one of the biggest problem was with wide string. Finally they gave up and until today we work on Lazarus beta version.

I'd like to ask what would you do on my place. Please, don't say "Change your job". I want to keep this project and improve it. Maybe there is a plugin which let me run old Free Pascal code on a newer version or some tool to convert old code. I heard that Delphi could handle old Free Pascal code bether than Lazarus but i'm not sure of that. Anyway, i would like your help.   

AlexTP

  • Hero Member
  • *****
  • Posts: 2353
    • UVviewsoft
Re: Projects written in old Free Pascal
« Reply #1 on: November 27, 2023, 01:57:02 pm »
Better show us the small test-demo with hard parts (parts taken from your work project). Why this demo is hard to update to Lazarus 2.0?

wp

  • Hero Member
  • *****
  • Posts: 11768
Re: Projects written in old Free Pascal
« Reply #2 on: November 27, 2023, 02:07:07 pm »
[...] because my project was primarly written on Turbo Pascal.
Does your project work in {$mode tp}?
https://www.freepascal.org/docs-html/prog/progse73.html

Handoko

  • Hero Member
  • *****
  • Posts: 5103
  • My goal: build my own game engine using Lazarus
Re: Projects written in old Free Pascal
« Reply #3 on: November 27, 2023, 03:07:55 pm »
It is mentioned, the code couldn't compile. So that were compile-time errors. What were the error messages? If it is hard to provide us a small test demo as mentioned, at least you should show us the error messages.

Actually fixing the code isn't too difficult, but it will take plenty of time. All you need to do is step-by-step recompile the code using higher version of Lazarus progressively.
Here is the list of all versions:
https://wiki.freepascal.org/Category:Release_Notes

Until you found the version that won't able to compile the code. For example, if you have no problem compiling until Lazarus version 0.9.30. Follow the link above and click the release note of Lazarus 0.9.30. There you will have information about "Changes affecting compatibility". That probably is the information you need.

But you also need to pay attention about the version of the FPC. You can read them in the link above, which have link started with "User Changes ..."

Alternatively. You can try by skipping some versions but if it fail, then you go down 1 version each time until you find the lowest un-compilable version.
« Last Edit: November 27, 2023, 03:19:20 pm by Handoko »

Bart

  • Hero Member
  • *****
  • Posts: 5234
    • Bart en Mariska's Webstek
Re: Projects written in old Free Pascal
« Reply #4 on: November 27, 2023, 06:42:21 pm »
As my collegue said, there was a huge change in Lazarus development propably between version 0.9.22 and 0.9.24
Looking at the release notes of 0.9.24, there aren't that many major changes.
Most notably, and indeed breaking, are the changes to TMaskEdit (all of them currently fixed).

B.t.w. what platform are you on (Windows, Linux, macOS)?

Bart

PS. IIRC then 0.9.22 was far from a stable version, it crashes repeatedly on my WinMe machine...
« Last Edit: November 27, 2023, 10:41:05 pm by Bart »

rigczTheSky

  • Newbie
  • Posts: 5
Re: Projects written in old Free Pascal
« Reply #5 on: November 27, 2023, 09:13:19 pm »
B.t.w. what platform are you on (Windows, Linux, macOS)?
Windows 11

rigczTheSky

  • Newbie
  • Posts: 5
Re: Projects written in old Free Pascal
« Reply #6 on: November 28, 2023, 12:04:41 am »
Ok. So i tried to create new Lazarus project on 2.26 version and paste some basic modules from the old one. When i tried to build it i've got a message from inc file:

Quote
filename.inc(254,27) Error: Call by var for arg no. 2 has to match exactly: Got "ShortString" expected "AnsiString"

Pasting
Code: Pascal  [Select][+][-]
  1. {$mode tp}
at the top of the file doesn't help. I know it would be better if I would show bigger sample of our code but i'am not sure if i can do that.

lainz

  • Hero Member
  • *****
  • Posts: 4400
    • https://lainz.github.io/
Re: Projects written in old Free Pascal
« Reply #7 on: November 28, 2023, 12:15:56 am »
Quote
filename.inc(254,27) Error: Call by var for arg no. 2 has to match exactly: Got "ShortString" expected "AnsiString"

Add this:

Code: Pascal  [Select][+][-]
  1. {$H+}

TRon

  • Hero Member
  • *****
  • Posts: 2229
Re: Projects written in old Free Pascal
« Reply #8 on: November 28, 2023, 01:23:01 am »
I know it would be better if I would show bigger sample of our code but i'am not sure if i can do that.
It would indeed be better (read quicker replies, more accurate answers) but in case you are unable to share then at the least provide:
- the exact error message
- the full line of code that triggers the error
- in case applicable, the complete header declaration of the function that the error line in question is trying to call
- all specifics about the variables used in the error line of code (type/var declaration, assignment etc) or for those that you are trying to pass to a function

If you are converting a larger project then it might be possible that the above is getting a long sequence of rinse and repeat but that comes with the territory of not being able to share larger portion of the code.

If you are lucky then all it takes are some compiler switches as already suggested by some (but it is a bit of a guessing game again due to lack of insight in the project you are working with).

cdbc

  • Hero Member
  • *****
  • Posts: 955
    • http://www.cdbc.dk
Re: Projects written in old Free Pascal
« Reply #9 on: November 28, 2023, 07:50:38 am »
Hi
@lainz & @TRon are right, it's a bit of work, but doable eg.:
Quote
filename.inc(254,27) Error: Call by var for arg no. 2 has to match exactly: Got "ShortString" expected "AnsiString"
Simply means that the calling unit is using shortstrings and the unit containing the function called is using ansistrings {$H+}
So you just have to trace back to the calling unit and at the top, just below the unitname, add {$H+} on its own line. Then this particular error, should go away... if not, then perhaps some of your strings are like S: string[80]; ie.: shortstrings and you must figure out why they're used?!?
Here's a snippet of one of my current units, from the top:
Code: Pascal  [Select][+][-]
  1. unit model.backend;
  2. {$mode ObjFPC}{$H+}
  3. {$ModeSwitch arrayoperators}
  4. interface                                            
  5. uses classes, sysutils...
  6.  
But that's for when you're further along and can try to modernize your codebase...
Hth
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Bart

  • Hero Member
  • *****
  • Posts: 5234
    • Bart en Mariska's Webstek
Re: Projects written in old Free Pascal
« Reply #10 on: November 28, 2023, 08:03:22 pm »
Quote
filename.inc(254,27) Error: Call by var for arg no. 2 has to match exactly: Got "ShortString" expected "AnsiString"

Add this:

Code: Pascal  [Select][+][-]
  1. {$H+}

All nice and well, but then make sure this unit is not using dirty shortstring tricks, like accessing string[0] to set the length, or access chars past the end of the string (eg. when length(s) = 10, and s is shortstring, you can store information in the bytes after s[10]).
The first example was a common practice in TP days.
(And I hope the old TP code doesn't use assembler routines to speed up string handling. I had lots of TP programs that did that.)

Bart

wp

  • Hero Member
  • *****
  • Posts: 11768
Re: Projects written in old Free Pascal
« Reply #11 on: November 28, 2023, 08:07:11 pm »
Pasting
Code: Pascal  [Select][+][-]
  1. {$mode tp}
at the top of the file doesn't help.
{$mode ...} is a per-unit directive, you must add it to every unit of your application (or, if you compile in the Lazarus IDE, change "Syntax mode" in "Project Options" > "Compiler Options" > "Parsing" to "Turbo Pascal (-Mtp)")

rigczTheSky

  • Newbie
  • Posts: 5
Re: Projects written in old Free Pascal
« Reply #12 on: December 18, 2023, 04:03:49 pm »
Ok, guys. Huge thanks for your efforts, but it seems to be more complicated. Before the release of version 0.9.24, our developer started making changes to the code on his own, which were then not compatible with future releases. So propably the biggest challenge for us is to solve conflicts between official releases and my company solutions.

Here is my plan:
1. download official repository from https://gitlab.com/freepascal.org/lazarus/lazarus.git
2. checkout on 09.22 commit
3. merge my company repository at this point
4. carefully move changes from newer Lazarus releases on my company branch

Everything goes fine through tree first steps. At point 4 any changes cause ZeosDBO problems during Lazarus rebuilding. Maybe it's because i don't know how to build an exe after checkout on another release. 

 

TinyPortal © 2005-2018