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“).
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.
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.
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“.
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.
Then click „compile“ and „install“.
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.