Recent

Author Topic: How to install JCL for Lazarus/FPC correctly?  (Read 8900 times)

MarkMacro

  • Newbie
  • Posts: 2
How to install JCL for Lazarus/FPC correctly?
« on: February 01, 2014, 09:30:37 am »
Hello everybody,

I’m not English, so excuse me, if there are some mistakes…
I'm pretty new to Lazarus and FPC. I worked with Delphi 7 many years ago and now I would like to do some programming stuff with Lazarus. I need to call a .NET dll function (disigned with C# VS2012 Express).
I found some helpful code for this here using JCL Package:
http://adamjohnston.me/2013/04/14/delphi-dotnet-interop-with-jvcl/

So I tried to install JCL package (version: jcl-2.4.1.4571) in Lazarus. From the JCL Wiki I understood that I have to install the jcl for FPC manually. What I did so far:
- start Lazarus and from Menu Package/Open Packagefile open Jcl.lpk from the jcl subfolder "jcl-2.4.1.4571\packages\fpc\Jcl.lpk"
- deleted all units except “mscorlib_TLB.pas” and “JclDotNet.pas” (because that is all I need for my project, I think)
- save package as new package (name: Jcl_custom.lpk)
- click on Compile.
- Now I got two Errors in unit JclStrings.pas:

E:\Downloads\jcl-2.4.1.4571\jcl-2.4.1.4571\source\common\JclStrings.pas(5383,10) Error: function header doesn't match the previous declaration "CompareNaturalStr(const AnsiString,const AnsiString):LongInt;"

E:\Downloads\jcl-2.4.1.4571\jcl-2.4.1.4571\source\common\JclStrings.pas(5388,10) Error: function header doesn't match the previous declaration "CompareNaturalText(const AnsiString,const AnsiString):LongInt;"

I changed the following function declarations in that way that I just deleted the “overload” from the functions:
function CompareNaturalStr(const S1, S2: string): SizeInt; overload;  <-delete overload
function CompareNaturalText(const S1, S2: string): SizeInt; overload;   <-delete overload

- recompile the package
- again an error of same kind in unit JclDateTime.pas:

E:\Downloads\jcl-2.4.1.4571\jcl-2.4.1.4571\source\common\JclDateTime.pas(266,10) Error: function header doesn't match the previous declaration "EncodeDate(const LongInt,Word,Word):Double;"

function EncodeDate(const Year: Integer; Month, Day: Word): TDateTime; overload;

I fixed it in the same way (deleted “overload” from function declaration).

- recompile the package
- again two errors of same kind in unit JclAnsiStrings.pas:

E:\Downloads\jcl-2.4.1.4571\jcl-2.4.1.4571\source\common\JclAnsiStrings.pas(4059,10) Error: function header doesn't match the previous declaration "AnsiCompareNaturalStr(const AnsiString,const AnsiString):LongInt;"

E:\Downloads\jcl-2.4.1.4571\jcl-2.4.1.4571\source\common\JclAnsiStrings.pas(4064,10) Error: function header doesn't match the previous declaration "AnsiCompareNaturalText(const AnsiString,const AnsiString):LongInt;"

function AnsiCompareNaturalStr(const S1, S2: AnsiString): SizeInt; overload;
function AnsiCompareNaturalText(const S1, S2: AnsiString): SizeInt; overload;

Again fixed it by deleting “overload”

- recompile the package
- Success!!! All files were compiled to the jcl subfolder: E:\Downloads\jcl-2.4.1.4571\jcl-2.4.1.4571\lib\fpc\i386-win32

- Go to Lazarus Menu/Package/Install Uninstall Packages. I found my new package and selected it for install then clicked on Save and Rebuild IDE.

However, I’m not able to use that package correctly. If I start a new project and put “mscorlib_TLB.pas” and “JclDotNet.pas” into the uses section the compiler cannot find these units.

What I did is the following: Created a new subfolder “jcl” in Lazarus:
C:\lazarus\fpc\2.6.2\units\i386-win32\jcl
Copied all .ppu .o -files which were successfully compiled from jcl package to that new subfolder. I also copied all source files (.pas) from jcl package to that folder.
After that, restarted Lazarus and started “Rescan FPC Source Directory”. Now I can use “mscorlib_TLB.pas” and “JclDotNet.pas” in my project.

However, finally it feels like trial and error doing so.
Is that the right way to install JCL? Is there any good tutorial on how installing jcl package?

My Sytem:
Win 7 64Bit
Lazarus 1.0.14
FPC: 2.6.2
JCL: jcl-2.4.1.4571
« Last Edit: February 01, 2014, 09:33:18 am by MarkMacro »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: How to install JCL for Lazarus/FPC correctly?
« Reply #1 on: February 01, 2014, 02:26:00 pm »
My guess is that you didn't link your newly created project to the package.

Lazarus has an important feature that it doesn't require store the paths of units in the project (making the project dependent on an installation).

Instead it allows you to let the project depend on the package, and auto adding the directory. (project->"Project Inspector"->"required Packages").

While this is actually a absolutely great feature, it is different from Delphi, and thus requires some getting used to. (but IMHO embarcadero should have done this ages ago)

Cyrax

  • Hero Member
  • *****
  • Posts: 836
Re: How to install JCL for Lazarus/FPC correctly?
« Reply #2 on: February 01, 2014, 04:53:17 pm »
You should get latest patch for JCL from here : http://issuetracker.delphi-jedi.org/view.php?id=5454

MarkMacro

  • Newbie
  • Posts: 2
Re: How to install JCL for Lazarus/FPC correctly?
« Reply #3 on: February 02, 2014, 06:53:43 pm »
Hello everybody,

Thanks a lot for that help. Finally I managed that svn- stuff to patch the jcl package and compiled it succesfully. I also linked my project to the package and everything is fine now. :D :D :D

Thanks a lot!

 

TinyPortal © 2005-2018