From 30926a4826bac59699fabae6c83a3c331caca60a Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 20 Jul 2022 09:12:16 +0000 Subject: [PATCH] tvplanit: Report duplicate resource error in ResEditDlg before exiting dialog. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8355 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/tvplanit/languages/demo.de.po | 1 + components/tvplanit/languages/demo.en.po | 1 + components/tvplanit/source/include/vpsr.inc | 2 +- components/tvplanit/source/vpbaseds.pas | 6 +++++ components/tvplanit/source/vpreseditdlg.lfm | 4 ++- components/tvplanit/source/vpreseditdlg.pas | 30 ++++++++++++++++++++- 6 files changed, 41 insertions(+), 3 deletions(-) diff --git a/components/tvplanit/languages/demo.de.po b/components/tvplanit/languages/demo.de.po index 3dbd1e21f..46d20f559 100644 --- a/components/tvplanit/languages/demo.de.po +++ b/components/tvplanit/languages/demo.de.po @@ -282,3 +282,4 @@ msgstr "Erledigte Aufgaben verbergen" #: tmainform.titlelbl.caption msgid "TitleLbl" msgstr "" + diff --git a/components/tvplanit/languages/demo.en.po b/components/tvplanit/languages/demo.en.po index b1e3db09d..5cb9d18ed 100644 --- a/components/tvplanit/languages/demo.en.po +++ b/components/tvplanit/languages/demo.en.po @@ -279,3 +279,4 @@ msgstr "Hide completed tasks" #: tmainform.titlelbl.caption msgid "TitleLbl" msgstr "TitleLbl" + diff --git a/components/tvplanit/source/include/vpsr.inc b/components/tvplanit/source/include/vpsr.inc index cb09793ca..293f5ed7f 100644 --- a/components/tvplanit/source/include/vpsr.inc +++ b/components/tvplanit/source/include/vpsr.inc @@ -237,7 +237,7 @@ resourcestring RSPrintBtn = '&Print'; RSUntitled = 'Untitled'; - {Sound Selection Dialog} + { Sound Selection Dialog } RSSelectASound = 'Select A Sound'; RSSoundFinder = 'Sound Finder'; RSDefaultSound = 'Use the default sound'; diff --git a/components/tvplanit/source/vpbaseds.pas b/components/tvplanit/source/vpbaseds.pas index a71a843d5..1b68ce037 100644 --- a/components/tvplanit/source/vpbaseds.pas +++ b/components/tvplanit/source/vpbaseds.pas @@ -310,6 +310,7 @@ type procedure UpdateGroupEvents; virtual; procedure DeleteResource(Res: TVpResource); + function FindResource(const AResourceName: String): TVpResource; property Connected : boolean read FConnected write SetConnected; property Loading : Boolean read FLoading write FLoading; @@ -536,6 +537,11 @@ begin PurgeResource(Res); end; +function TVpCustomDataStore.FindResource(const AResourceName: String): TVpResource; +begin + Result := FResources.FindResourceByName(AResourceName); +end; + {=====} procedure TVpCustomDataStore.DeregisterAllWatchers; diff --git a/components/tvplanit/source/vpreseditdlg.lfm b/components/tvplanit/source/vpreseditdlg.lfm index a9f2bf7ba..fdeef5e41 100644 --- a/components/tvplanit/source/vpreseditdlg.lfm +++ b/components/tvplanit/source/vpreseditdlg.lfm @@ -12,7 +12,7 @@ object ResEditForm: TResEditForm Constraints.MinWidth = 400 OnCreate = FormCreate OnShow = FormShow - LCLVersion = '1.6.4.0' + LCLVersion = '2.3.0.0' object pnlBottom: TPanel Left = 0 Height = 33 @@ -79,6 +79,7 @@ object ResEditForm: TResEditForm Width = 63 BorderSpacing.Left = 8 Caption = 'Description:' + Color = clDefault ParentColor = False end object lblNotes: TLabel @@ -91,6 +92,7 @@ object ResEditForm: TResEditForm Width = 34 BorderSpacing.Top = 8 Caption = 'Notes:' + Color = clDefault ParentColor = False end object imgResources: TImage diff --git a/components/tvplanit/source/vpreseditdlg.pas b/components/tvplanit/source/vpreseditdlg.pas index 09849c49d..2ada04be9 100644 --- a/components/tvplanit/source/vpreseditdlg.pas +++ b/components/tvplanit/source/vpreseditdlg.pas @@ -41,7 +41,7 @@ uses SysUtils, {$IFDEF VERSION6} Variants, {$ENDIF} Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, - VpDlg, VpBase, VpData, VpConst; + VpDlg, VpBase, VpBaseDS, VpData, VpConst; type { forward declarations } @@ -64,14 +64,17 @@ type procedure FormShow(Sender: TObject); procedure OKBtnClick(Sender: TObject); private + FDatastore: TVpCustomDatastore; procedure PositionControls; procedure SetControls; + function ValidData(out AControl: TWinControl; out AMsg: String): Boolean; public ReturnCode: TVpEditorReturnCode; ResourceChanged: Boolean; Resource: TVpResource; procedure PopulateSelf; procedure DePopulateSelf; + property Datastore: TVpCustomDatastore read FDatastore write FDatastore; end; TVpResourceEditDialog = class(TVpBaseDialog) @@ -158,6 +161,7 @@ begin Application.CreateForm(TResEditForm, EditForm); try DoFormPlacement(EditForm); + EditForm.Datastore := Datastore; EditForm.Resource := reResource; EditForm.PopulateSelf; EditForm.ShowModal; @@ -220,11 +224,35 @@ begin end; procedure TResEditForm.OKBtnClick(Sender: TObject); +var + C: TWinControl; + msg: String; begin + if ResourceChanged and not ValidData(C, msg) then + begin + C.SetFocus; + MessageDlg(msg, mtError, [mbOK], 0); + exit; + end; + if ResourceChanged then ReturnCode := rtCommit; Close; end; + +function TResEditForm.ValidData(out AControl: TWinControl; out AMsg: String): Boolean; +begin + Result := false; + + if FDatastore.FindResource(DescriptionEdit.Text) <> nil then + begin + AControl := DescriptionEdit; + AMsg := RSDuplicateResource; + exit; + end; + + Result := true; +end; {=====} procedure TResEditForm.FormCreate(Sender: TObject);