From d45aef853670f9b826d3c6bca1aee485098c5b2d Mon Sep 17 00:00:00 2001 From: graemeg Date: Mon, 8 Sep 2008 15:09:18 +0000 Subject: * added an extra check to StringGrid list mediator. * Default all auto generated data to posClean. * Added some Debug buttons in forms to view raw data properties. --- .../demos/Demo_21_AdrsBook_MGM/contactmanager.pas | 15 +++++++++- .../demos/Demo_21_AdrsBook_MGM/frmcitymaint.pas | 33 +++++++++++++++++++--- .../demos/Demo_21_AdrsBook_MGM/frmcontactmaint.pas | 33 +++++++++++++++++++++- extras/tiopf/gui/tiListMediators.pas | 10 ++++--- 4 files changed, 81 insertions(+), 10 deletions(-) (limited to 'extras/tiopf') diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/contactmanager.pas b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/contactmanager.pas index 1bd34a1c..94c876ee 100644 --- a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/contactmanager.pas +++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/contactmanager.pas @@ -39,7 +39,7 @@ function gContactManager: TContactManager; implementation uses - SysUtils; + SysUtils, tiObject; var uContactManager: TContactManager; @@ -65,6 +65,8 @@ end; { TContactManager } procedure TContactManager.PopulateCountries; +var + i: integer; begin FCountryList.Add(TCountry.CreateNew('za', 'South Africa')); FCountryList.Add(TCountry.CreateNew('gb', 'Great Britain')); @@ -72,11 +74,16 @@ begin FCountryList.Add(TCountry.CreateNew('fr', 'France')); FCountryList.Add(TCountry.CreateNew('us', 'United States')); FCountryList.Add(TCountry.CreateNew('gr', 'Germany')); + + { reset ObjectState property } + for i := 0 to FCountryList.Count - 1 do + FCountryList[i].ObjectState := posClean; end; procedure TContactManager.PopulateCities; var c: TCity; + i: integer; begin c:= TCity.CreateNew; c.Name:= 'Somerset West'; @@ -143,6 +150,10 @@ begin c.ZIP := 'BC5 7WN'; c.Country:= TCountry(FCountryList.FindByProps(['ISO'], ['uk'], True)); FCityList.Add(c); + + { reset ObjectState property } + for i := 0 to FCityList.Count - 1 do + FCityList[i].ObjectState := posClean; end; function TContactManager.GenPhone: string; @@ -196,9 +207,11 @@ begin A.Telephone1:= GenPhone; If Random(2)>0 then A.Telephone2:= GenPhone; + A.Dirty := False; C.AddressList.Add(A); end; C.Comments := 'My name is ' + C.FirstName + '.'; + C.ObjectState := posClean; FContactList.Add(C); end; end; diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitymaint.pas b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitymaint.pas index 01db6ea2..64aa988d 100644 --- a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitymaint.pas +++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcitymaint.pas @@ -23,11 +23,13 @@ type cbCountry: TfpgComboBox; btnSave: TfpgButton; btnCancel: TfpgButton; + btnDebug: TfpgButton; {@VFD_HEAD_END: CityEditForm} FMediator: TFormMediator; FData: TCity; procedure SetData(const AValue: TCity); procedure SetupMediators; + procedure btnDebugClicked(Sender: TObject); public procedure AfterCreate; override; property Data: TCity read FData write SetData; @@ -41,7 +43,7 @@ function EditCity(AData: TCity): boolean; implementation uses - tiBaseMediator, tiMediators, contactmanager, typinfo; + tiBaseMediator, tiMediators, contactmanager, typinfo, tiDialogs; function EditCity(AData: TCity): boolean; @@ -82,11 +84,16 @@ begin FMediator.Active := True; end; +procedure TCityEditForm.btnDebugClicked(Sender: TObject); +begin + tiShowString(FData.AsDebugString); +end; + procedure TCityEditForm.AfterCreate; begin {@VFD_BODY_BEGIN: CityEditForm} Name := 'CityEditForm'; - SetPosition(673, 204, 260, 186); + SetPosition(673, 204, 350, 186); WindowTitle := 'City Maintenance'; lblName1 := TfpgLabel.Create(self); @@ -95,6 +102,7 @@ begin Name := 'lblName1'; SetPosition(8, 8, 80, 16); FontDesc := '#Label1'; + Hint := ''; Text := 'City name:'; end; @@ -114,6 +122,7 @@ begin Name := 'lblName2'; SetPosition(8, 52, 80, 16); FontDesc := '#Label1'; + Hint := ''; Text := 'ZIP code:'; end; @@ -133,6 +142,7 @@ begin Name := 'lblName3'; SetPosition(8, 96, 80, 16); FontDesc := '#Label1'; + Hint := ''; Text := 'Country:'; end; @@ -149,10 +159,11 @@ begin with btnSave do begin Name := 'btnSave'; - SetPosition(92, 156, 80, 24); + SetPosition(182, 156, 80, 24); Anchors := [anRight,anBottom]; Text := 'Save'; FontDesc := '#Label1'; + Hint := ''; ImageName := ''; TabOrder := 6; ModalResult := mrOK; @@ -162,15 +173,29 @@ begin with btnCancel do begin Name := 'btnCancel'; - SetPosition(176, 156, 80, 24); + SetPosition(266, 156, 80, 24); Anchors := [anRight,anBottom]; Text := 'Cancel'; FontDesc := '#Label1'; + Hint := ''; ImageName := ''; TabOrder := 7; ModalResult := mrCancel; end; + btnDebug := TfpgButton.Create(self); + with btnDebug do + begin + Name := 'btnDebug'; + SetPosition(8, 156, 100, 24); + Text := 'Debug (Show)'; + FontDesc := '#Label1'; + Hint := ''; + ImageName := ''; + TabOrder := 8; + OnClick := @btnDebugClicked; + end; + {@VFD_BODY_END: CityEditForm} end; diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcontactmaint.pas b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcontactmaint.pas index 8a8aeb1c..e414937c 100644 --- a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcontactmaint.pas +++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmcontactmaint.pas @@ -34,11 +34,13 @@ type btnAdd: TfpgButton; btnEdit: TfpgButton; btnDelete: TfpgButton; + btnDebug: TfpgButton; {@VFD_HEAD_END: ContactEditForm} FMediator: TFormMediator; FAdrsMediator: TFormMediator; procedure SetData(const AValue: TContact); procedure SetupMediators; + procedure btnDebugClicked(Sender: TObject); public procedure AfterCreate; override; property Data: TContact read FData write SetData; @@ -52,7 +54,7 @@ function EditContact(AData: TContact): Boolean; implementation uses - contactmanager; + contactmanager, tiDialogs; function EditContact(AData: TContact): Boolean; @@ -95,6 +97,11 @@ begin FAdrsMediator.Active := True; end; +procedure TContactEditForm.btnDebugClicked(Sender: TObject); +begin + tiShowString(FData.AsDebugString); +end; + procedure TContactEditForm.SetData(const AValue: TContact); begin if FData=AValue then exit; @@ -115,6 +122,7 @@ begin Name := 'lblName1'; SetPosition(8, 8, 80, 16); FontDesc := '#Label1'; + Hint := ''; Text := 'Firstname:'; end; @@ -134,6 +142,7 @@ begin Name := 'lblName2'; SetPosition(8, 52, 80, 16); FontDesc := '#Label1'; + Hint := ''; Text := 'Lastname:'; end; @@ -153,6 +162,7 @@ begin Name := 'lblName3'; SetPosition(8, 96, 80, 16); FontDesc := '#Label1'; + Hint := ''; Text := 'EMail:'; end; @@ -172,6 +182,7 @@ begin Name := 'lblName4'; SetPosition(8, 140, 80, 16); FontDesc := '#Label1'; + Hint := ''; Text := 'Mobile:'; end; @@ -191,6 +202,7 @@ begin Name := 'lblName5'; SetPosition(8, 184, 80, 16); FontDesc := '#Label1'; + Hint := ''; Text := 'Comments:'; end; @@ -210,6 +222,7 @@ begin Name := 'lblName6'; SetPosition(264, 8, 80, 16); FontDesc := '#Label1'; + Hint := ''; Text := 'Addresses:'; end; @@ -229,6 +242,7 @@ begin SetPosition(364, 300, 80, 24); Text := 'Save'; FontDesc := '#Label1'; + Hint := ''; ImageName := ''; TabOrder := 12; ModalResult := mrOK; @@ -241,6 +255,7 @@ begin SetPosition(448, 300, 80, 24); Text := 'Cancel'; FontDesc := '#Label1'; + Hint := ''; ImageName := ''; TabOrder := 13; ModalResult := mrCancel; @@ -253,6 +268,7 @@ begin SetPosition(264, 152, 52, 24); Text := 'Add'; FontDesc := '#Label1'; + Hint := ''; ImageName := ''; TabOrder := 14; end; @@ -264,6 +280,7 @@ begin SetPosition(320, 152, 52, 24); Text := 'Edit'; FontDesc := '#Label1'; + Hint := ''; ImageName := ''; TabOrder := 15; end; @@ -275,10 +292,24 @@ begin SetPosition(376, 152, 52, 24); Text := 'Delete'; FontDesc := '#Label1'; + Hint := ''; ImageName := ''; TabOrder := 16; end; + btnDebug := TfpgButton.Create(self); + with btnDebug do + begin + Name := 'btnDebug'; + SetPosition(8, 300, 100, 24); + Text := 'Debug (Show)'; + FontDesc := '#Label1'; + Hint := ''; + ImageName := ''; + TabOrder := 17; + OnClick := @btnDebugClicked; + end; + {@VFD_BODY_END: ContactEditForm} end; diff --git a/extras/tiopf/gui/tiListMediators.pas b/extras/tiopf/gui/tiListMediators.pas index 94a84163..4bfe06b4 100644 --- a/extras/tiopf/gui/tiListMediators.pas +++ b/extras/tiopf/gui/tiListMediators.pas @@ -177,11 +177,9 @@ end; function TListViewMediator.GetSelectedObject: TtiObject; begin -// if FView.SelCount = 0 then if FView.ItemIndex = -1 then Result := nil else -// FSelectedObject := TtiObject(FView.Selected.Data); Result := TtiObject(FView.Items.Item[FView.ItemIndex].UserData); end; @@ -411,11 +409,15 @@ end; function TStringGridMediator.GetSelectedObject: TtiObject; begin + if FView.RowCount = 0 then + begin + Result := nil; + Exit; + end; + if FView.FocusRow = -1 then -// if FView.Selection.Top = 0 then Result := nil else -// Result := TtiObject(FView.Objects[1, FView.Selection.Top]); Result := TtiObject(FView.Objects[0, FView.FocusRow]); end; -- cgit v1.2.3-70-g09d2