How to use Freepascal 2 with the Key Objects Library
by Thaddy de Koning

 

 

With the release of version 2.0.0 the Freepascal team reached a new height in compatibility with Delphi. The Key Objects library has long since supported Freepascal, with a set of conditional defines and special library add-ons. Now, however, the Freepascal 2 compiler is compatible enough to compile Kol.pas  without any changes. You can alternatively download a fully prepared package here. That file contains the necessary support files to compile Kol applications and some examples

You can also download only these support files.

Note: there are actually two alternatives to using the prepared support files:

  1. You can use the Freepascal version of the win32api files from the JEDI project.
  2. If you own a Delphi version with sourcecode, you can use the source\rtl\win\ units with freepascal 2

This is because Freepascal has still some quirky Windows API translations.

Preparing FPC.CFG

In order to work with KOL, we will either have to pass the right compiler settings when we compile, or adapt FPC.CFG. These are my own settings for kolfpc.cfg which have proven to work reliably. I recommend you save the file to the left as kolfpc.cfg in your kol source directory and use the following commandline parameters to compile:

>fpc -n @kolfpc.cfg -dRELEASE <SOURCE>

#Adapt the paths to point to your own FPC directory

-Fuc:\FPC\/units/$FPCTARGET/
-Fuc:\FPC\/units/$FPCTARGET/*
-Fuc:\FPC\/units/$FPCTARGET/rtl
-Fuc:\FPC\kol

# For a release compile with optimizes and strip debuginfo
#IFDEF RELEASE
-Og1p2
-Xs
#KOL
-Mdelphi
-CX
-Sg

#WRITE Compiling Release Version
#ENDIF

# For a debug version compile with debuginfo and all codegeneration checks on

#IFDEF DEBUG
-gcl
-Crtoi
-Sg
#KOL
-Sa
-Mdelphi
#WRITE Compiling Debug Version
#ENDIF

Preparing delphidef.inc

Simply comment ASM_VERSION with a dot like so: {.$DEFINE ASM VERSION} or add {$DEFINE PAS_VERSION}

Example project

In order to check if everything is ok, here's a small example program that we now should be able to compile:

Save it as project1.dpr and compile it like this:

>fpc -n @kolfpc.cfg -dRELEASE project1.dpr

You should end up with a nice executable of about 40K in size.

 

 

program Project1;
{$APPTYPE GUI}
uses
	Kol;
begin
  Applet:=NewForm(nil,'Basic FPC');
  Run(Applet);
end.