summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/gui/gridtest/gridtest.lpi1
-rw-r--r--examples/gui/gridtest/gridtest.lpr35
-rw-r--r--extras/tiopf/demos/Demo_21_AdrsBook_MGM/frmmain.pas46
-rw-r--r--extras/tiopf/demos/Demo_21_AdrsBook_MGM/model.pas12
-rw-r--r--extras/tiopf/gui/tiListMediators.pas3
-rw-r--r--src/gui/fpg_customgrid.pas9
-rw-r--r--src/gui/fpg_grid.pas15
7 files changed, 92 insertions, 29 deletions
diff --git a/examples/gui/gridtest/gridtest.lpi b/examples/gui/gridtest/gridtest.lpi
index 4dcc44f4..25664143 100644
--- a/examples/gui/gridtest/gridtest.lpi
+++ b/examples/gui/gridtest/gridtest.lpi
@@ -9,7 +9,6 @@
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
- <IconPath Value="./"/>
<TargetFileExt Value=""/>
</General>
<VersionInfo>
diff --git a/examples/gui/gridtest/gridtest.lpr b/examples/gui/gridtest/gridtest.lpr
index c6753332..56afaa10 100644
--- a/examples/gui/gridtest/gridtest.lpr
+++ b/examples/gui/gridtest/gridtest.lpr
@@ -32,18 +32,20 @@ type
chkShowGrid: TfpgCheckBox;
chkRowSelect: TfpgCheckBox;
chkDisabled: TfpgCheckBox;
+ chkHideFocus: TfpgCheckBox;
edtTopRow: TfpgEditInteger;
btnTopRow: TfpgButton;
btnAddFive: TfpgButton;
btnAddOne: TfpgButton;
btnFiveOnly: TfpgButton;
- chkHideFocus: TfpgCheckBox;
+ btnDelRow: TfpgButton;
{@VFD_HEAD_END: MainForm}
procedure StringGridDoubleClicked(Sender: TObject; AButton: TMouseButton;
AShift: TShiftState; const AMousePos: TPoint);
procedure btnAddFiveClicked(Sender: TObject);
procedure btnAddOneClicked(Sender: TObject);
procedure btnFiveOnlyClicked(Sender: TObject);
+ procedure btnDelRowClicked(Sender: TObject);
procedure chkDisabledChange(Sender: TObject);
procedure chkRowSelectChange(Sender: TObject);
procedure chkShowHeaderChange(Sender: TObject);
@@ -85,6 +87,11 @@ begin
StringGrid.RowCount := 5;
end;
+procedure TMainForm.btnDelRowClicked(Sender: TObject);
+begin
+ stringgrid.DeleteRow(stringgrid.FocusRow);
+end;
+
procedure TMainForm.chkDisabledChange(Sender: TObject);
begin
stringgrid.Enabled := not chkDisabled.Checked;
@@ -159,6 +166,7 @@ begin
Anchors := [anRight,anBottom];
Text := 'Quit';
FontDesc := '#Label1';
+ Hint := '';
ImageName := 'stdimg.Quit';
OnClick := @btnQuitClick;
end;
@@ -169,7 +177,6 @@ begin
Name := 'stringgrid';
SetPosition(10, 10, 375, 250);
Anchors := [anLeft,anRight,anTop,anBottom];
- AddColumn('Column 0', 65);
AddColumn('Column 1', 100, taLeftJustify);
AddColumn('Col 2', 50, taCenter);
AddColumn('Numbers', 150, taRightJustify);
@@ -177,6 +184,7 @@ begin
HeaderFontDesc := '#GridHeader';
RowCount := 17;
TabOrder := 1;
+ AddColumn('Column 0', 65);
// Alignment test
Cells[1, 2] := 'left';
Cells[2, 2] := 'center';
@@ -275,6 +283,7 @@ begin
Anchors := [anLeft,anBottom];
Text := 'Set TopRow';
FontDesc := '#Label1';
+ Hint := '';
ImageName := '';
TabOrder := 7;
OnClick := @btnTopRowClicked;
@@ -284,10 +293,11 @@ begin
with btnAddFive do
begin
Name := 'btnAddFive';
- SetPosition(188, 280, 80, 23);
+ SetPosition(168, 280, 80, 23);
Anchors := [anLeft,anBottom];
Text := 'Add 5 lines';
FontDesc := '#Label1';
+ Hint := '';
ImageName := '';
TabOrder := 8;
OnClick := @btnAddFiveClicked;
@@ -297,10 +307,11 @@ begin
with btnAddOne do
begin
Name := 'btnAddOne';
- SetPosition(272, 280, 80, 23);
+ SetPosition(252, 280, 80, 23);
Anchors := [anLeft,anBottom];
Text := 'Add 1 line';
FontDesc := '#Label1';
+ Hint := '';
ImageName := '';
TabOrder := 9;
OnClick := @btnAddOneClicked;
@@ -310,15 +321,29 @@ begin
with btnFiveOnly do
begin
Name := 'btnFiveOnly';
- SetPosition(356, 280, 80, 23);
+ SetPosition(336, 280, 80, 23);
Anchors := [anLeft,anBottom];
Text := '5 lines only';
FontDesc := '#Label1';
+ Hint := '';
ImageName := '';
TabOrder := 10;
OnClick := @btnFiveOnlyClicked;
end;
+ btnDelRow := TfpgButton.Create(self);
+ with btnDelRow do
+ begin
+ Name := 'btnDelRow';
+ SetPosition(168, 308, 80, 23);
+ Text := 'Delete Row';
+ FontDesc := '#Label1';
+ Hint := '';
+ ImageName := '';
+ TabOrder := 12;
+ OnClick := @btnDelRowClicked;
+ end;
+
{@VFD_BODY_END: MainForm}
for r := 0 to stringgrid.RowCount-1 do
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;
diff --git a/src/gui/fpg_customgrid.pas b/src/gui/fpg_customgrid.pas
index 7b042799..b5a6c191 100644
--- a/src/gui/fpg_customgrid.pas
+++ b/src/gui/fpg_customgrid.pas
@@ -91,6 +91,7 @@ type
destructor Destroy; override;
function AddColumn(ATitle: string; AWidth: integer): TfpgGridColumn; virtual;
procedure DeleteColumn(AIndex: integer); virtual;
+ procedure DeleteRow(AIndex: integer); virtual;
procedure MoveColumn(oldindex, newindex: integer); virtual;
end;
@@ -351,6 +352,14 @@ begin
end;
end;
+procedure TfpgCustomGrid.DeleteRow(AIndex: integer);
+begin
+ if (AIndex < 0) or (AIndex > FRowCount-1) then
+ Exit;
+ { This is just some sanity checking. Actual row deletion must occur in
+ descendant classed. See TfpgStringGrid for an example. }
+end;
+
procedure TfpgCustomGrid.MoveColumn(oldindex, newindex: integer);
begin
FColumns.Move(oldindex, newindex);
diff --git a/src/gui/fpg_grid.pas b/src/gui/fpg_grid.pas
index 72fd29bf..3eecf7c1 100644
--- a/src/gui/fpg_grid.pas
+++ b/src/gui/fpg_grid.pas
@@ -106,6 +106,7 @@ type
constructor Create(AOwner: TComponent); override;
function AddColumn(ATitle: string; AWidth: integer; AAlignment: TAlignment = taLeftJustify;
AbackgroundColor: TfpgColor = clDefault; ATextColor: TfpgColor = clDefault): TfpgStringColumn; overload;
+ procedure DeleteRow(AIndex: integer); override;
property Cells[ACol, ARow: Integer]: string read GetCell write SetCell;
property Objects[ACol, ARow: Integer]: TObject read GetObjects write SetObjects;
property ColumnTitle[ACol: Integer]: string read GetColumnTitle write SetColumnTitle;
@@ -513,5 +514,19 @@ begin
Updated; // if we called .BeginUpdate then don't clear csUpdating here
end;
+procedure TfpgCustomStringGrid.DeleteRow(AIndex: integer);
+var
+ c: integer;
+begin
+ inherited DeleteRow(AIndex); // does sanity checks
+ for c := 0 to FColumns.Count-1 do
+ begin
+ TfpgStringColumn(FColumns[c]).Cells.Delete(AIndex);
+ end;
+ FRowCount := FRowCount-1;
+ if HasHandle then
+ Update;
+end;
+
end.