Recent

Author Topic: Using Jedi Code Format from inside a program  (Read 1704 times)

simone

  • Sr. Member
  • ****
  • Posts: 263
Using Jedi Code Format from inside a program
« on: November 12, 2018, 11:12:14 pm »
I'd like to use JCF to format object pascal code generated by my program.

I want to use JCF in my program as a library. How I can do this?
« Last Edit: November 13, 2018, 07:06:39 am by simone »

simone

  • Sr. Member
  • ****
  • Posts: 263
Re: Using Jedi Code Format from inside a program
« Reply #1 on: November 24, 2018, 08:50:08 pm »
Since I have received no answer, I try to better explain my question. I have created a program that generates object pascal code. I'd like to use JCF in my code generator to format the generated code. I currently get this result using JCF as external command line utility, launching the executable with TProcess.Execute. How could I use the JCF as component in my code, in a similar way as Lazarus does? Can any of the Lazarus developers explain to me how the IDE uses the JCF library? Thanks to those who can give me some useful suggestions.

lucamar

  • Hero Member
  • *****
  • Posts: 2147
Re: Using Jedi Code Format from inside a program
« Reply #2 on: November 24, 2018, 09:13:28 pm »
Not much and it's almost completely undocumented but look into {YourLazarusRoot}/components/jcf2/IdePlugin/ to see how the "interface" between Lazarus and JCF works.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

simone

  • Sr. Member
  • ****
  • Posts: 263
Re: Using Jedi Code Format from inside a program
« Reply #3 on: November 25, 2018, 04:46:48 pm »
I understood how to 'interface' a GUI application with the JCF library. I share what I have learned with the forum, in the hope that it will be useful to someone. First of all, the package jcfidelazarus.lpk must be added to the project (From the IDE: Package>OpenPackageFile, then Use>AddToProject). The package is distributed with Lazarus in the following folder:

{LazarusBaseDir}\components\jcf2\IdePlugin\lazarus

At this point the unit Converter mus be added in the uses statement of program.

Now the following steps are required:
- create an aConverter object of TConverter class;
- set aConverter.InputCode property string with the code to format;
- invoke aConverter.Convert method;
- retrieve the formatted code placed in aConverter.OutputCode string property;
- handle possible errors according to aConverter.ConvertError boolean property.

In attached zip there is a program demo that shows a basic usage of JCF package.

P.S.: The presence of configuration file JCFSettings.cfg is mandatory.
 
 
« Last Edit: November 25, 2018, 06:46:17 pm by simone »