For a couple of years now, the Free Pascal RAD IDE Lazarus is well supported by Advantage Database Server. In this little tutorial I want to show how to use the actual ADS components in Lazarus.
First of all, get Lazarus (http://www.lazarus-ide.org/) and the „ADS 12 evaluation for Win32“ as described here. After installing Lazarus, extract the ADS 12 evaluation zip file.
It is recommended, to use Advantage Data Architect (ARC) to create and administer databases. The installer of ARC can be found in the ADS 12 install folder („arc32.exe“).

Advantage Data Architect InstallShield Wizard
Advantage Data Architect InstallShield Wizard

By default, the wizard also installs a sample database. This database is located in „C:\Program Files (x86)\Advantage 12.0\help\ADS_DATA“. Due to the location, it is readonly. To work around, copy the database folder to a different location (e.g. to „C:\databases“). Database aliases (for Data Architect, Delphi, and Lazarus applications) are stored in the „ads.ini“ file, which by default is located in the Windows folder. To create new aliases, you need to move that file to a folder with write permissions (e.g. „C:\databases“) and create a system environment variable named „adsini_path“ that points to that folder.
Setting up the system variable adsini_path
Setting up the system variable adsini_path

After this initial setup, launch ARC, right click the alias „ADTDemoData“ in the „Connection Repository“ and select „Connection Properties“. This will open up a dialog box to configure the „ConnectionPath“ of the database (point it to your location, e.g. „C:\databases\ADS_DATA\“) and other Properties. If you didn’t install the server component of Advantaga Database Server, set „ServerType“ to „local“. Click „Ok“ to save and close the dialog. Double click the alias to connect and then expand the TABLES entry to get a list of tables. Open some of the tables by double clicking to make sure this works.
Advantage Data Architect
Advantage Data Architect

The Lazarus components are part of the Delphi installation („adsdelphi.exe“). During installation, a Custom Setup dialog box allows you to select „Lazarus Free Pascal“.
Delphi Setup Options
Delphi Setup Options

This will install the required component packages and source files into „C:\Program Files (x86)\Advantage 12.0\TDataset\Lazarus“.
In Lazarus, all packages have to be compiled into the IDE itself. To add the Advantage components, open up the Lazarus IDE, click on „Package“, then „Open Package File (.lpk) …“ and browse to the „adsl.lpk“ file in the TDataset Lazarus folder.
Select Lazarus Package File
Select Lazarus Package File

Then click „compile“ and „install“.
Install ADS Package
Install ADS Package

Lazarus will now prompt to recompile and then restart the IDE. Click „Yes“ to continue. After restart, a new tab named „Advantage“ appears in the component palette.
For a first demo, create a new project and place a TAdsConnection, TAdsTable, TDataSource, TDBGrid, and TDBNavigator to the form. Double click the form to edit the source of the FormCreate event handler and add following code:

procedure TForm1.FormCreate(Sender: TObject);
begin
  AdsConnection1.AliasName:='ADTDemoData';
  AdsConnection1.AdsServerTypes:=[stADS_LOCAL];
  AdsConnection1.Connect;
  AdsTable1.AdsConnection:=AdsConnection1;
  AdsTable1.TableName:='biolife';
  AdsTable1.Open;
  DataSource1.DataSet:=AdsTable1;
  DBNavigator1.DataSource:=DataSource1;
  DBNavigator1.Align:=alTop;
  DBGrid1.DataSource:=DataSource1;
  DBGrid1.Align:=alClient;
end;    

You also need to add „adsset“ to the uses list. Then press „F9“ to comile and run the project … and done.

First Lazarus Application
First Lazarus Application

Tutorial: using ADS with Lazarus
Markiert in:                     

3 Kommentare zu „Tutorial: using ADS with Lazarus

  • 20. April 2016 um 13:21 Uhr
    Permalink

    Things don’t look nice at all if you have a newer version of lazarus and german umlauts in the table and field type is not „nchar“. All umlauts will bei replaced with „?“. If one use the famous trick with OnGetText using AnsiToUTF8 and OnSetText using UTF8ToAnsi all umlauts will be replaced with „�“. meh.

    Antworten
    • 21. April 2016 um 16:39 Uhr
      Permalink

      right. But a google search reveals that this affects other databases aswell. Semms to be an issue with Lazarus. I couldn’t find a quick solution so far.

      Antworten
      • 12. Mai 2016 um 15:10 Uhr
        Permalink

        You have to set -dDisableUTF8RTL in project options. After that, Lazarus 1.6 behaves like Lazarus 1.44.

        Antworten

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert