diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-09-18 15:05:54 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-09-18 15:05:54 +0000 |
commit | 3ec9a96b3feea6448b74706cecd38fbb7b53d994 (patch) | |
tree | fd67e80985a6491a5277f82ac9533eb9b621d1b2 | |
parent | 4a9d0f5ff9ced813e373b76833db958a560d75f6 (diff) | |
download | fpGUI-3ec9a96b3feea6448b74706cecd38fbb7b53d994.tar.xz |
* Update Demo 08 to work with latest changes in tiOPF - except for SqlDB support.
-rw-r--r-- | extras/tiopf/demos/Demo_08_Collection/demo_08.lpi | 19 | ||||
-rw-r--r-- | extras/tiopf/demos/Demo_08_Collection/demo_08.lpr | 14 | ||||
-rw-r--r-- | extras/tiopf/demos/Demo_08_Collection/frm_main.pas | 71 | ||||
-rw-r--r-- | extras/tiopf/demos/Demo_08_Collection/mediators.pas | 17 |
4 files changed, 62 insertions, 59 deletions
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 @@ <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> </local> </RunParams> - <RequiredPackages Count="2"> + <RequiredPackages Count="1"> <Item1> - <PackageName Value="fpgui_package"/> - </Item1> - <Item2> <PackageName Value="tiOPFfpGUI"/> - </Item2> + </Item1> </RequiredPackages> - <Units Count="7"> + <Units Count="6"> <Unit0> <Filename Value="demo_08.lpr"/> <IsPartOfProject Value="True"/> @@ -67,24 +64,16 @@ <IsPartOfProject Value="True"/> <UnitName Value="Client_DBIndependentVisitors_Svr"/> </Unit5> - <Unit6> - <Filename Value="mediators.pas"/> - <IsPartOfProject Value="True"/> - <UnitName Value="mediators"/> - </Unit6> </Units> </ProjectOptions> <CompilerOptions> - <Version Value="5"/> + <Version Value="8"/> <Parsing> <SyntaxOptions> <AllowLabel Value="False"/> <CPPInline Value="False"/> </SyntaxOptions> </Parsing> - <CodeGeneration> - <Generate Value="Faster"/> - </CodeGeneration> <Other> <CustomOptions Value="-FUunits -dUseCThreads"/> 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 <Client>'); 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. - |