Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building Delphi project from Visual Studio Code

I have already set up build and debug environment for Object Pascal inside Visual Studio Code via FPC and GDB, but I just made build process work for programs containing only 1 .pas file via

"command": "fpc",
"args": [ "-g", "-Px86_64", "helloWorld.pas" ],

Now, I need to build quite big Delphi project group (something like solution?) and it contains main project file .groupproj.

Is there a way to build the .groupproj via FPC somehow?
Or at least some workaround like conversion to .lpi and then build via FPC?
Or at least call Delphi compiler/builder from VS Code and build the whole project group via it? (but I don't like this option, because I prefer to not use Delphi)

like image 930
Lukas Salich Avatar asked Apr 12 '17 13:04

Lukas Salich


People also ask

Can you code Delphi in Visual Studio?

No. Delphi is not one of the languages that is supported in Visual Studio.

Can I create a project in VS Code?

In VS Code, type in “Create C++ Project” in the main prompt. This is a functionality of the Generator extension, which will guide you through the project creation process. Use “Open > Folder” to open the newly created C++ project in VS Code.

How do I run Pascal code in Visual Studio?

OmniPascal - Open Preview - Visual Studio Marketplace Once the extension is installed, go to File → Preferences → Settings and find the “OmniPascal configuration” section under “Extensions”. For the Free Pascal Source Path, enter the path to a folder that contains the Free Pascal source, e.g.


1 Answers

To get some facts straight for other people that might stumble on this:

  • FPC supports Delphi source files (.lpr/.dpr, .pp/.pas and .inc). Not Delphi meta information (.dproj/.dof/.bpg/.cfg/.groupproj) which is Delphi version dependent anyway.
  • Lazarus conversion tool also converts .dfms. Basically it is a .dfm cleaner and Uses clause enhancer, just like some conversion tools between Delphi versions. It by default however also does substitutions that change Delphi code (that works in FPC's Delphi (-Sd) mode) into the objfpc dialect (-S2 mode) preferred by Lazarus . Always make a backup before trying, and check the configuration of the conversion tool thoroughly.
  • FPC and Delphi commandline parameters are different.
  • FPC does not support Lazarus metadata formats like .lpi. The Lazarus utility Lazbuild however does support building Lazarus projects from the commandline.

But luckily the basics are the same

  1. a main program or library file files)
  2. a set of unit (.pas files) and include directories (.inc files). FPC differentiates between the two, delphi doesn't.
  3. autocreated forms must be added to the project.
  4. any additional commandline switches like defines to set, range checking optimization options.

So in worst case, examine the Delphi projects (either in IDE or texteditor) for directories and switches and create either a manual buildscript or a lazarus (.lpi) project.

However it is vital to keep in mind that the default FPC mode is NOT Delphi mode, so always when executing FPC make sure you manually enable Delphi mode (-Sd)

Group project support within Lazarus is very new (as in months), and afaik not even in stable versions yet. Though if you create a bunch of .lpis, a batch file/shellscript with a sequence of lazbuild commands on .lpis might do it.

P.s. throw the VSCode under the bus and use Lazarus.

like image 187
Marco van de Voort Avatar answered Sep 19 '22 22:09

Marco van de Voort