From 9577a278f84e3795d0ee5a5e2e28f60c9fff84b8 Mon Sep 17 00:00:00 2001 From: graemeg Date: Fri, 31 Oct 2008 09:54:03 +0000 Subject: * Implemented virtual RowDelete() method for TfpgCustomGrid. * Implemented full RowDelete() for TfpgStringGrid. * Updated tiListMediators to use the new RowDelete() method of StringGrid. * Updated the GridTest demo to show RowDelete() in action. * Updated the AddressBook Demo 21 to enable deleting of contacts. --- .../tiopf/demos/Demo_21_AdrsBook_MGM/frmmain.pas | 46 ++++++++++++++++------ extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas | 12 +----- extras/tiopf/gui/tiListMediators.pas | 3 +- 3 files changed, 38 insertions(+), 23 deletions(-) (limited to 'extras') diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmmain.pas b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmmain.pas index d589e20b..dd5029e5 100644 --- a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmmain.pas +++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmmain.pas @@ -5,10 +5,12 @@ unit frmmain; interface uses - SysUtils, Classes, fpg_base, fpg_main, fpg_edit, - fpg_widget, fpg_form, fpg_label, fpg_button, - fpg_basegrid, fpg_grid, fpg_dialogs, fpg_menu, - fpg_panel, fpg_popupcalendar, fpg_gauge, tiFormMediator; + SysUtils, Classes, + { fpGUI Toolkit } + fpg_base, fpg_main, fpg_widget, fpg_form, fpg_button, + fpg_grid, fpg_dialogs, fpg_menu, + { tiOPF } + tiFormMediator; type { The main application window } @@ -47,7 +49,7 @@ implementation uses model, contactmanager, tiListMediators, tiBaseMediator, tiMediators, - frmcontactmaint, frmcitylist, frmcountrylist; + frmcontactmaint, frmcitylist, frmcountrylist, tiDialogs, tiObject; {@VFD_NEWFORM_IMPL} @@ -89,22 +91,45 @@ var c: TContact; rowmed: TStringGridRowMediator; begin + if grdContacts.FocusRow < 0 then + begin + tiAppError('You need to select a Contact first'); + Exit; + end; rowmed := TStringGridRowMediator(TStringGridMediator(FMediator.FindByComponent(grdContacts).Mediator).SelectedObject); c := TContact(rowmed.Model); -// tiShowString(c.AsDebugString); if not Assigned(c) then Exit; //==> if EditContact(c) then begin - // we can save contact here + // we can save contact here if we wanted end; end; procedure TMainForm.miEditDeleteClick(Sender: TObject); +var + c: TContact; + rowmed: TStringGridRowMediator; begin - // + if grdContacts.FocusRow < 0 then + begin + tiAppError('You need to select a Contact first'); + Exit; + end; + rowmed := TStringGridRowMediator(TStringGridMediator(FMediator.FindByComponent(grdContacts).Mediator).SelectedObject); + c := TContact(rowmed.Model); + + if tiAppConfirmation('Are you sure you want to delete <%s>', [c.FirstName + ' ' + c.LastName]) then + begin + { We can't use .Deleted property here, because we don't actually save + changes. This means the ObjectState will only be posDelete and not + posDeleted, which is what .FreeDeleted is looking for. } +// c.Deleted := True; + c.ObjectState := posDeleted; + gContactManager.ContactList.FreeDeleted; + end; end; procedure TMainForm.miSystemCityList(Sender: TObject); @@ -182,7 +207,6 @@ begin ImageName := ''; TabOrder := 3; OnClick := @miEditDeleteClick; - Enabled := False; end; MainMenu := TfpgMenuBar.Create(self); @@ -206,9 +230,9 @@ begin begin Name := 'miEdit'; SetPosition(344, 156, 120, 20); - AddMenuItem('Add Contact', '', @miEditAddClick).Enabled := False; + AddMenuItem('Add Contact', '', @miEditAddClick); AddMenuItem('Edit Contact', '', @miEditEditClick); - AddMenuItem('Delete Contact', '', @miEditDeleteClick).Enabled := False; + AddMenuItem('Delete Contact', '', @miEditDeleteClick); end; miSystem := TfpgPopupMenu.Create(self); diff --git a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas index bf8e289a..3ffa07c3 100644 --- a/extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas +++ b/extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas @@ -123,7 +123,6 @@ type procedure SetTelephone2(const AValue: string); public constructor Create; override; - destructor Destroy; override; procedure AssignClassProps(ASource: TtiObject); override; published property Street: string read FStreet write SetStreet; @@ -342,20 +341,13 @@ end; constructor TAddress.Create; begin inherited Create; - FAddressType:= TAddressType.Create; - FAddressType.Owner:= self; -end; - -destructor TAddress.Destroy; -begin - FreeAndNil(FAddressType); - inherited Destroy; + FAddressType := nil; end; procedure TAddress.AssignClassProps(ASource: TtiObject); begin FAddressType := TAddress(ASource).AddressType; // reference only - FCity:= TAddress(ASource).City; // reference only + FCity := TAddress(ASource).City; // reference only end; procedure TAddress.SetNr(const AValue: integer); diff --git a/extras/tiopf/gui/tiListMediators.pas b/extras/tiopf/gui/tiListMediators.pas index 566d75f9..92e8c93e 100644 --- a/extras/tiopf/gui/tiListMediators.pas +++ b/extras/tiopf/gui/tiListMediators.pas @@ -441,8 +441,7 @@ end; procedure TStringGridMediator.DoDeleteItemMediator(AIndex: Integer; AMediator: TListItemMediator); begin - {$Warning Implement DeleteColRow in StringGrid } -// FView.DeleteColRow(False,AIndex+1); + FView.DeleteRow(AIndex); inherited DoDeleteItemMediator(AIndex, AMediator); end; -- cgit v1.2.3-70-g09d2