From 395e3f20ed42e657c4b09d01c14dee5a0b57788b Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 2 Sep 2016 17:58:47 +0000 Subject: [PATCH] tvplanit: Add a mORMot variant of the full demo (based on code kindly provided by DonAlfredo). git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5123 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/fulldemo/bufdsdatamodule.lfm | 37 ++++++ .../examples/fulldemo/bufdsdatamodule.pas | 31 +++++ .../tvplanit/examples/fulldemo/demo.lpi | 10 +- .../tvplanit/examples/fulldemo/demo.lpr | 2 +- .../tvplanit/examples/fulldemo/demomain.pas | 60 ++++----- .../examples/fulldemo/mormotdatamodule.lfm | 14 +++ .../examples/fulldemo/mormotdatamodule.pas | 64 ++++++++++ .../tvplanit/examples/fulldemo/mormotdemo.lpi | 117 ++++++++++++++++++ .../tvplanit/examples/fulldemo/mormotdemo.lpr | 23 ++++ components/tvplanit/source/vpwavdlg.lfm | 1 + 10 files changed, 323 insertions(+), 36 deletions(-) create mode 100644 components/tvplanit/examples/fulldemo/bufdsdatamodule.lfm create mode 100644 components/tvplanit/examples/fulldemo/bufdsdatamodule.pas create mode 100644 components/tvplanit/examples/fulldemo/mormotdatamodule.lfm create mode 100644 components/tvplanit/examples/fulldemo/mormotdatamodule.pas create mode 100644 components/tvplanit/examples/fulldemo/mormotdemo.lpi create mode 100644 components/tvplanit/examples/fulldemo/mormotdemo.lpr diff --git a/components/tvplanit/examples/fulldemo/bufdsdatamodule.lfm b/components/tvplanit/examples/fulldemo/bufdsdatamodule.lfm new file mode 100644 index 000000000..ed89e3420 --- /dev/null +++ b/components/tvplanit/examples/fulldemo/bufdsdatamodule.lfm @@ -0,0 +1,37 @@ +object DemoDM: TDemoDM + OldCreateOrder = False + Height = 150 + HorizontalOffset = 603 + VerticalOffset = 519 + Width = 277 + object Datastore: TVpBufDSDataStore + CategoryColorMap.Category0.Color = clNavy + CategoryColorMap.Category0.Description = 'Category 0' + CategoryColorMap.Category1.Color = clRed + CategoryColorMap.Category1.Description = 'Category 1' + CategoryColorMap.Category2.Color = clYellow + CategoryColorMap.Category2.Description = 'Category 2' + CategoryColorMap.Category3.Color = clLime + CategoryColorMap.Category3.Description = 'Category 3' + CategoryColorMap.Category4.Color = clPurple + CategoryColorMap.Category4.Description = 'Category 4' + CategoryColorMap.Category5.Color = clTeal + CategoryColorMap.Category5.Description = 'Category 5' + CategoryColorMap.Category6.Color = clFuchsia + CategoryColorMap.Category6.Description = 'Category 6' + CategoryColorMap.Category7.Color = clOlive + CategoryColorMap.Category7.Description = 'Category 7' + CategoryColorMap.Category8.Color = clAqua + CategoryColorMap.Category8.Description = 'Category 8' + CategoryColorMap.Category9.Color = clMaroon + CategoryColorMap.Category9.Description = 'Category 9' + EnableEventTimer = True + PlayEventSounds = True + AutoConnect = True + AutoCreate = True + DayBuffer = 31 + Directory = 'data' + left = 87 + top = 32 + end +end diff --git a/components/tvplanit/examples/fulldemo/bufdsdatamodule.pas b/components/tvplanit/examples/fulldemo/bufdsdatamodule.pas new file mode 100644 index 000000000..def38cb49 --- /dev/null +++ b/components/tvplanit/examples/fulldemo/bufdsdatamodule.pas @@ -0,0 +1,31 @@ +unit bufdsdatamodule; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, VpBaseDS, VpBufDS; + +type + + { TDemoDM } + + TDemoDM = class(TDataModule) + Datastore: TVpBufDSDataStore; + private + + public +// constructor Create(AOwner: TComponent); override; + + end; + +var + DemoDM: TDemoDM; + +implementation + +{$R *.lfm} + +end. + diff --git a/components/tvplanit/examples/fulldemo/demo.lpi b/components/tvplanit/examples/fulldemo/demo.lpi index a7e7c2e71..3316d39ff 100644 --- a/components/tvplanit/examples/fulldemo/demo.lpi +++ b/components/tvplanit/examples/fulldemo/demo.lpi @@ -64,11 +64,11 @@ - + + - @@ -92,6 +92,12 @@ + + + + + + diff --git a/components/tvplanit/examples/fulldemo/demo.lpr b/components/tvplanit/examples/fulldemo/demo.lpr index 5f7bdb17c..7ea82f940 100644 --- a/components/tvplanit/examples/fulldemo/demo.lpr +++ b/components/tvplanit/examples/fulldemo/demo.lpr @@ -8,7 +8,7 @@ uses {$ENDIF}{$ENDIF} Interfaces, // this includes the LCL widgetset Forms, demoMain, laz_visualplanit, LCLTranslator, DefaultTranslator, - printer4lazarus, demoDatamodule; + bufdsdatamodule, printer4lazarus; {$R *.res} diff --git a/components/tvplanit/examples/fulldemo/demomain.pas b/components/tvplanit/examples/fulldemo/demomain.pas index 557e3fd71..c9cbce209 100644 --- a/components/tvplanit/examples/fulldemo/demomain.pas +++ b/components/tvplanit/examples/fulldemo/demomain.pas @@ -9,12 +9,10 @@ uses clocale, {$ENDIF} Classes, SysUtils, FileUtil, PrintersDlgs, Forms, Controls, Graphics, Dialogs, - ExtCtrls, StdCtrls, ComCtrls, LCLTranslator, Menus, LCLVersion, -// VpBufDS, - VpBaseDS, VpDayView, - VpWeekView, VpTaskList, VpAbout, VpContactGrid, VpMonthView, VpResEditDlg, - VpContactButtons, VpNavBar, VpData, VpPrtPrvDlg, VpPrtFmtDlg, Types, - VpBase, VpCalendar; + ExtCtrls, StdCtrls, ComCtrls, LCLTranslator, Menus, Types, LCLVersion, + VpBaseDS, VpDayView, VpWeekView, VpTaskList, VpAbout, VpContactGrid, + VpMonthView, VpResEditDlg, VpContactButtons, VpNavBar, VpData, + VpPrtPrvDlg, VpPrtFmtDlg, VpBase, VpCalendar; type @@ -171,8 +169,13 @@ uses {$ENDIF} IniFiles, Math, Printers, VpMisc, VpPrtFmt, - demoDatamodule, - sound, ExVpRptSetup; + sound, ExVpRptSetup, + + // Using the defines BUFDATASET or MORMOT (defined in project options) we + // select the datastore to use in this demo. + {$IFDEF BUFDATASET}BufDSDatamodule{$ENDIF} + {$IFDEF MORMOT}mORMotDatamodule{$ENDIF} + ; const LANGUAGE_DIR = '..\..\languages\'; @@ -408,13 +411,19 @@ end; // Load the last resource. procedure TMainForm.FormCreate(Sender: TObject); -var - lastRes: TVpResource; begin - (* - Datastore := TVpBufDSDatastore.Create(self); + PopulateLanguages; + ReadIni; - with Datastore as TVpBufDSDatastore do begin + // Establish connection of datastore (resides in a datamodule) to all + // dependent controls. + VpControlLink1.Datastore := DemoDM.Datastore; + + with VpControlLink1.Datastore do begin + + // These properties could be set also in Object Inspector. + // But we do it here at runtime because the mORMot datastore is + // created at runtime, and we want both versions to behave the same. CategoryColorMap.Category0.BackgroundColor := clSkyBlue; CategoryColorMap.Category0.Color := clNavy; CategoryColorMap.Category0.Description := 'Appointment'; @@ -430,32 +439,17 @@ begin CategoryColorMap.Category4.BackgroundColor := 15332329; CategoryColorMap.Category4.Color := clMoneyGreen; CategoryColorMap.Category4.Description := 'Private'; - EnableEventTimer := True; - PlayEventSounds := True; + + PlayEventSounds := true; OnPlaySound := @VpBufDSDataStore1PlaySound; {$IFDEF WINDOWS} MediaFolder := AppendPathDelim(SysUtils.GetEnvironmentVariable('SYSTEMROOT')) + 'media'; {$ENDIF} - DayBuffer := 31; - Directory := 'data'; - Connected := true; - end; - VpControlLink1.Datastore := Datastore; - *) - // Establish connection of datastore (resides in a datamodule) to all - // dependent controls. - VpControlLink1.Datastore := DemoDM.VpBufDSDatastore1; - - PopulateLanguages; - ReadIni; - - with VpControlLink1.Datastore do + // By default select the last resource entered. if Resources.Count > 0 then - begin - lastRes := Resources.Items[Resources.Count-1]; - Resource := lastRes; - end; + Resource := Resources.Items[Resources.Count-1]; + end; end; procedure TMainForm.MnuAboutClick(Sender: TObject); diff --git a/components/tvplanit/examples/fulldemo/mormotdatamodule.lfm b/components/tvplanit/examples/fulldemo/mormotdatamodule.lfm new file mode 100644 index 000000000..18806b6d1 --- /dev/null +++ b/components/tvplanit/examples/fulldemo/mormotdatamodule.lfm @@ -0,0 +1,14 @@ +object DemoDM: TDemoDM + OldCreateOrder = False + Height = 150 + HorizontalOffset = 280 + VerticalOffset = 130 + Width = 447 + object Timer1: TTimer + Enabled = False + Interval = 250 + OnTimer = Timer1Timer + left = 62 + top = 34 + end +end diff --git a/components/tvplanit/examples/fulldemo/mormotdatamodule.pas b/components/tvplanit/examples/fulldemo/mormotdatamodule.pas new file mode 100644 index 000000000..f3e816e41 --- /dev/null +++ b/components/tvplanit/examples/fulldemo/mormotdatamodule.pas @@ -0,0 +1,64 @@ +unit mormotdatamodule; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, FileUtil, Forms, Dialogs, ExtCtrls, VpmORMotDS; + +type + + { TDemoDM } + + TDemoDM = class(TDataModule) + Timer1: TTimer; + procedure Timer1Timer(Sender: TObject); + private + public + Datastore: TVpmORMotDatastore; + constructor Create(AOwner: TComponent); override; + end; + +var + DemoDM: TDemoDM; + +implementation + +{$R *.lfm} + +constructor TDemoDM.Create(AOwner: TComponent); +begin + inherited; + + Datastore := TVpmORMotDatastore.Create(self); + + with Datastore do + begin + // if the HostIP is set, it will look for a running server on this IP address when connecting. + // leave blank (comment out) for a local (and private) database + + HostIP := 'localhost'; + Directory := 'data'; + Connected := true; + + if (Length(HostIP)>0) and (not Connected) then + begin + MessageDlg('Cannot connect with server', mtError, [mbOk], 0); + Application.Terminate; + end; + end; + + Timer1.Enabled := true; +end; + +procedure TDemoDM.Timer1Timer(Sender: TObject); +begin + Timer1.Enabled := False; + Datastore.CheckUpdate; + Timer1.Enabled := True; +end; + + +end. + diff --git a/components/tvplanit/examples/fulldemo/mormotdemo.lpi b/components/tvplanit/examples/fulldemo/mormotdemo.lpi new file mode 100644 index 000000000..6eb07818f --- /dev/null +++ b/components/tvplanit/examples/fulldemo/mormotdemo.lpi @@ -0,0 +1,117 @@ + + + + + + + + + + <ResourceType Value="res"/> + <UseXPManifest Value="True"/> + </General> + <i18n> + <EnableI18N Value="True"/> + <OutDir Value="..\..\languages"/> + </i18n> + <VersionInfo> + <StringTable ProductVersion=""/> + </VersionInfo> + <BuildModes Count="1"> + <Item1 Name="Default" Default="True"/> + </BuildModes> + <PublishOptions> + <Version Value="2"/> + </PublishOptions> + <RunParams> + <local> + <FormatVersion Value="1"/> + </local> + </RunParams> + <RequiredPackages Count="3"> + <Item1> + <PackageName Value="Printer4Lazarus"/> + </Item1> + <Item2> + <PackageName Value="laz_visualplanit"/> + </Item2> + <Item3> + <PackageName Value="LCL"/> + </Item3> + </RequiredPackages> + <Units Count="5"> + <Unit0> + <Filename Value="mormotdemo.lpr"/> + <IsPartOfProject Value="True"/> + </Unit0> + <Unit1> + <Filename Value="demomain.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="MainForm"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + <UnitName Value="demoMain"/> + </Unit1> + <Unit2> + <Filename Value="sound.pas"/> + <IsPartOfProject Value="True"/> + </Unit2> + <Unit3> + <Filename Value="ExVpRptSetup.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="frmReportSetup"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="Form"/> + </Unit3> + <Unit4> + <Filename Value="mormotdatamodule.pas"/> + <IsPartOfProject Value="True"/> + <ComponentName Value="DemoDM"/> + <HasResources Value="True"/> + <ResourceBaseClass Value="DataModule"/> + </Unit4> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="11"/> + <PathDelim Value="\"/> + <Target> + <Filename Value="mormotdemo"/> + </Target> + <SearchPaths> + <IncludeFiles Value="$(ProjOutDir);..\mormot\mORMotSourceHere;..\..\source"/> + <Libraries Value="..\mormot\mORMotSourceHere\fpc-win32"/> + <OtherUnitFiles Value="..\mormot;..\mormot\mORMotSourceHere;..\mormot\mORMotSourceHere\SQLite3"/> + <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/> + </SearchPaths> + <Linking> + <Debugging> + <UseExternalDbgSyms Value="True"/> + </Debugging> + <Options> + <Win32> + <GraphicApplication Value="True"/> + </Win32> + </Options> + </Linking> + <Other> + <CustomOptions Value="-dMORMOT"/> + <OtherDefines Count="1"> + <Define0 Value="MORMOT"/> + </OtherDefines> + </Other> + </CompilerOptions> + <Debugging> + <Exceptions Count="3"> + <Item1> + <Name Value="EAbort"/> + </Item1> + <Item2> + <Name Value="ECodetoolError"/> + </Item2> + <Item3> + <Name Value="EFOpenError"/> + </Item3> + </Exceptions> + </Debugging> +</CONFIG> diff --git a/components/tvplanit/examples/fulldemo/mormotdemo.lpr b/components/tvplanit/examples/fulldemo/mormotdemo.lpr new file mode 100644 index 000000000..007546a07 --- /dev/null +++ b/components/tvplanit/examples/fulldemo/mormotdemo.lpr @@ -0,0 +1,23 @@ +program mormotdemo; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Interfaces, // this includes the LCL widgetset + Forms, demoMain, laz_visualplanit, LCLTranslator, DefaultTranslator, + printer4lazarus, mormotdatamodule; + +{$R *.res} + +begin + Application.Title := 'mORMot Demo'; + RequireDerivedFormResource := True; + Application.Initialize; + Application.CreateForm(TDemoDM, DemoDM); + Application.CreateForm(TMainForm, MainForm); + Application.Run; +end. + diff --git a/components/tvplanit/source/vpwavdlg.lfm b/components/tvplanit/source/vpwavdlg.lfm index 81c6dbac9..234880f74 100644 --- a/components/tvplanit/source/vpwavdlg.lfm +++ b/components/tvplanit/source/vpwavdlg.lfm @@ -129,6 +129,7 @@ object FrmSoundDialog: TFrmSoundDialog Color = clDefault HideSelection = False Mask = '*.wav' + ReadOnly = True TabOrder = 1 ObjectTypes = [otNonFolders] ShellTreeView = ShellTreeView