[Lazarus] Help clarify use of TApplication with tiOPF example.

Frank Church vfclists at gmail.com
Sat Mar 12 16:01:49 CET 2011


I just compiled tiOPF and I am going through the examples which are
converted from Delphi, and I am using it to understand how Lazarus GUI
projects are organized

The first one I tried was this project. The program is supposed creates a
dialog which probably depends on the LCL, so in order to get it work I
created a new project, added a form to it, triggered the dialog from the
form, then proceeded to minimize the app via experimentation until the form
was not needed.

Below is the original project source, and following it is the Lazarus
project. I guess Delphi projects automatically include some of the units
with have to be added explicitly to the Lazarus project.

program Demo_LoadPersistenceLayerIfDef;
>
> // Adding a {$DEFINE LINK_???} to your project, either in the DPR
> // or the Project | Options - Conditional Defines dialog,
> // the specified persistence layers will be linked and loaded.
> //
> // When you run this demo, a dialog will show listing
> // the loaded persistence layers. (Note, the dialog will
> // say the database is not connected - wich is correct.)
>
> // Take a look at tiOPFManager about line 215 you will see how
> // this the defines are implemented.
>
> {$R *.res}
>
> uses
>   DemoDBUtils in '..\Common\DemoDBUtils.pas';
>
> begin
>   ShowConnectedDatabases;
> end.
>

Here is the pared down Lazarus equivalent

program Demo_LoadPersistenceLayerIfDef_Laz;
>
> {$mode objfpc}{$H+}
>
> uses
>   {$IFDEF UNIX}{$IFDEF UseCThreads}
>   cthreads,
>   {$ENDIF}{$ENDIF}
>   Interfaces, // this includes the LCL widgetset
>   Forms, //frmMain,
>   LResources,
>   { you can add units after this }
>   DemoDBUtils in '..\Common\DemoDBUtils.pas';
>
> {$IFDEF WINDOWS}{$R Demo_LoadPersistenceLayerIfDef_Laz.rc}{$ENDIF}
>
> begin
>   {$I Demo_LoadPersistenceLayerIfDef_Laz.lrs}
>   Application.Initialize;
>   //Application.CreateForm(TForm1, Form1);
>   //Application.Run;
>   DemoDBUtils.ShowConnectedDatabases;
> end.
>

I want to know if in order to display the dialog the project could be pared
down further.
Is there some way to get the dialog to show if the project did not use
TApplication?

Are the .rc files and .lrs files also required?

below is the DemoDBUtils unit for more clarification

unit DemoDBUtils;
>
> interface
>
> procedure ShowConnectedDatabases;
>
> implementation
> uses
>   tiOPFManager
>   ,tiUtils
>   ,tiDialogs
>   ,SysUtils
>  ;
>
> procedure ShowConnectedDatabases;
> var
>   i: integer;
>   LS: string;
> begin
>   LS:= '';
>   for i:= 0 to GTIOPFManager.PersistenceLayers.Count - 1 do
>   begin
>     if LS <> '' then
>       LS:= LS + Cr;
>     if
> Trim(GTIOPFManager.PersistenceLayers.Items[i].DBConnectionPools.DetailsAsString)
> = '' then
>       LS:= LS + 'Persistence layer: "'+
> GTIOPFManager.PersistenceLayers.Items[i].PersistenceLayerName +
>             '" loaded, but not connected to a database.' + Cr
>     else
>       LS:= LS +
> GTIOPFManager.PersistenceLayers.Items[i].DBConnectionPools.DetailsAsString +
> Cr
>   end;
>
>   if LS <> '' then
>     tiAppMessage(LS)
>   else
>     tiAppMessage('No persistence layers loaded');
> end;
> end.
>


-- 
Frank Church

=======================
http://devblog.brahmancreations.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20110312/646bc34c/attachment-0002.html>


More information about the Lazarus mailing list