From 3ec9a96b3feea6448b74706cecd38fbb7b53d994 Mon Sep 17 00:00:00 2001 From: graemeg Date: Thu, 18 Sep 2008 15:05:54 +0000 Subject: * Update Demo 08 to work with latest changes in tiOPF - except for SqlDB support. --- extras/tiopf/demos/Demo_08_Collection/demo_08.lpi | 19 ++---- extras/tiopf/demos/Demo_08_Collection/demo_08.lpr | 14 ++++- extras/tiopf/demos/Demo_08_Collection/frm_main.pas | 71 ++++++++++++++-------- .../tiopf/demos/Demo_08_Collection/mediators.pas | 17 ------ 4 files changed, 62 insertions(+), 59 deletions(-) delete mode 100644 extras/tiopf/demos/Demo_08_Collection/mediators.pas diff --git a/extras/tiopf/demos/Demo_08_Collection/demo_08.lpi b/extras/tiopf/demos/Demo_08_Collection/demo_08.lpi index 9e6af029..f8e27367 100644 --- a/extras/tiopf/demos/Demo_08_Collection/demo_08.lpi +++ b/extras/tiopf/demos/Demo_08_Collection/demo_08.lpi @@ -28,15 +28,12 @@ - + - - - - + - + @@ -67,24 +64,16 @@ - - - - - - + - - - diff --git a/extras/tiopf/demos/Demo_08_Collection/demo_08.lpr b/extras/tiopf/demos/Demo_08_Collection/demo_08.lpr index de16545a..67acbdd2 100644 --- a/extras/tiopf/demos/Demo_08_Collection/demo_08.lpr +++ b/extras/tiopf/demos/Demo_08_Collection/demo_08.lpr @@ -2,6 +2,10 @@ program demo_08; {$mode objfpc}{$H+} +// Which persistence layer to activate. (Un)Comment the one you want to use +{.$define UseFBL} +{$define UseSqldbIB} + uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, @@ -9,7 +13,7 @@ uses Classes, SysUtils, fpgfx, frm_main, Client_DBIndependentVisitors_Svr, Client_BOM, Client_AutoMap_Svr, Client_HardCodedVisitors_Svr, tiOPFManager, - tiConstants, mediators; + tiConstants{, tiLog, tiLogToConsole}; procedure MainProc; var @@ -17,10 +21,18 @@ var begin fpgApplication.Initialize; + {$IFDEF UseFBL} if GTIOPFManager.PersistenceLayers.FindByPersistenceLayerName(cTIPersistFBL) = nil then raise Exception.Create('The system failed to find the <' + cTIPersistFBL + '> persistence layer') else GTIOPFManager.DefaultPersistenceLayerName := cTIPersistFBL; + {$ENDIF} + {$IFDEF UseSqldbIB} + if GTIOPFManager.PersistenceLayers.FindByPersistenceLayerName(cTIPersistSqldbIB) = nil then + raise Exception.Create('The system failed to find the <' + cTIPersistSqldbIB + '> persistence layer') + else + GTIOPFManager.DefaultPersistenceLayerName := cTIPersistSqldbIB; + {$ENDIF} { Change the connection string to suite your database location } // ** Remote connection diff --git a/extras/tiopf/demos/Demo_08_Collection/frm_main.pas b/extras/tiopf/demos/Demo_08_Collection/frm_main.pas index eabcf56c..9db19cc1 100644 --- a/extras/tiopf/demos/Demo_08_Collection/frm_main.pas +++ b/extras/tiopf/demos/Demo_08_Collection/frm_main.pas @@ -10,24 +10,12 @@ uses gui_listbox, gui_memo, gui_combobox, gui_grid, gui_dialogs, gui_checkbox, gui_tree, gui_trackbar, gui_progressbar, gui_radiobutton, gui_tab, gui_menu, - gui_bevel, Client_BOM, mediators; + gui_bevel, Client_BOM, tiFormMediator; type TMainForm = class(TfpgForm) private - FClients: TClients; - FmedClients: TClient_StringGrid_Mediator; - procedure MainFormShow(Sender: TObject); - procedure CreateTable; - procedure DropTable; - function TableExists: boolean; - procedure btnInsertRowClick(Sender: TObject); - procedure btnDeleteRowClick(Sender: TObject); - procedure btnSaveClick(Sender: TObject); - procedure btnReadClick(Sender: TObject); - procedure btnShowClick(Sender: TObject); - public {@VFD_HEAD_BEGIN: MainForm} lblName1: TfpgLabel; lblName2: TfpgLabel; @@ -42,6 +30,19 @@ type btnRead: TfpgButton; grdCollection: TfpgStringGrid; {@VFD_HEAD_END: MainForm} + FClients: TClients; + FMediator: TFormMediator; + procedure MainFormShow(Sender: TObject); + procedure CreateTable; + procedure DropTable; + procedure CreateMediators; + function TableExists: boolean; + procedure btnInsertRowClick(Sender: TObject); + procedure btnDeleteRowClick(Sender: TObject); + procedure btnSaveClick(Sender: TObject); + procedure btnReadClick(Sender: TObject); + procedure btnShowClick(Sender: TObject); + public constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure AfterCreate; override; @@ -59,15 +60,22 @@ uses ,tiOID ,tiDialogs ,tiConstants + ,tiBaseMediator + ,tiListMediators + ,tiLog ; {@VFD_NEWFORM_IMPL} procedure TMainForm.MainFormShow(Sender: TObject); begin + Log('Creating mediators'); + CreateMediators; // Drop and re-create to be sure we start with the correct structure + Log('Testing if table exists'); if TableExists then begin + Log(' Should we drop and recreate the tables'); if TfpgMessageDialog.Question(ApplicationName, 'Must we delete existing data?', mbYesNo) = mbYes then begin DropTable; @@ -99,6 +107,25 @@ begin gTIOPFManager.DropTable('Client'); end; +procedure TMainForm.CreateMediators; +begin + if not Assigned(FMediator) then + begin + FMediator := TFormMediator.Create(self); + FMediator.AddComposite('ClientName(200,"Client name");ClientID(80,"Client ID")', grdCollection); + end; + FMediator.Subject := FClients; + FMediator.Active := True; + + //FmedClients := TClient_StringGrid_Mediator.CreateCustom(FClients, grdCollection, 'ClientName(200,"Client name");ClientID(80,"Client ID")'); + //FClients.NotifyObservers; + + //LV.AddColumn(LVDeriveOID, 'OID', 270); + //LV.AddColumn('ClientName', vttkString, 'Client name', 200); + //LV.AddColumn('ClientID', vttkString, 'Client ID', 80); + //LV.Data:= FClients; +end; + function TMainForm.TableExists: boolean; var LDBMetaData: TtiDBMetaData; @@ -108,7 +135,9 @@ begin try LDatabase := gTIOPFManager.DefaultDBConnectionPool.Lock; try +// Log(' Reading meta data of tables'); LDatabase.ReadMetaDataTables(LDBMetaData); +// log(' Finding the table '); result := LDBMetaData.FindByTableName('Client') <> nil; finally gTIOPFManager.DefaultDBConnectionPool.UnLock(LDatabase); @@ -124,7 +153,6 @@ var begin LClient:= TClient.CreateNew; FClients.Add(LClient); - //LV.Refresh(LClient); end; procedure TMainForm.btnDeleteRowClick(Sender: TObject); @@ -143,9 +171,6 @@ procedure TMainForm.btnReadClick(Sender: TObject); begin FClients.Clear; FClients.Read; - //LV.Refresh; - FmedClients := TClient_StringGrid_Mediator.CreateCustom(FClients, grdCollection, 'ClientName(200,"Client name");ClientID(80,"Client ID")'); - FClients.NotifyObservers; end; procedure TMainForm.btnShowClick(Sender: TObject); @@ -159,19 +184,11 @@ begin WindowTitle := 'Connected to ' + gTIOPFManager.DefaultDBConnectionName; FClients := TClients.Create; OnShow := @MainFormShow; - - //FmedClients := TClient_StringGrid_Mediator.CreateCustom(FClients, grdCollection, 'ClientName(200,"Client name");ClientID(80,"Client ID")'); - //FClients.NotifyObservers; - - //LV.AddColumn(LVDeriveOID, 'OID', 270); - //LV.AddColumn('ClientName', vttkString, 'Client name', 200); - //LV.AddColumn('ClientID', vttkString, 'Client ID', 80); - //LV.Data:= FClients; end; destructor TMainForm.Destroy; begin - FmedClients.Free; + FMediator.Active := False; FClients.Free; inherited Destroy; end; @@ -306,5 +323,7 @@ begin {@VFD_BODY_END: MainForm} end; +initialization + gMediatorManager.RegisterMediator(TStringGridMediator, TClients); end. diff --git a/extras/tiopf/demos/Demo_08_Collection/mediators.pas b/extras/tiopf/demos/Demo_08_Collection/mediators.pas deleted file mode 100644 index a316f32f..00000000 --- a/extras/tiopf/demos/Demo_08_Collection/mediators.pas +++ /dev/null @@ -1,17 +0,0 @@ -unit mediators; - -{$mode objfpc}{$H+} - -interface - -uses - tiCompositeMediators; - -type - TClient_StringGrid_Mediator = class(TCompositeStringGridMediator) - end; - -implementation - -end. - -- cgit v1.2.3-70-g09d2