summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-06-18 22:14:40 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2008-06-18 22:14:40 +0000
commit19fb9140056fa79aac6ccd25018bb5175ccfc0d0 (patch)
tree008ee0d0060917f696004a9534106f48dd14884a /src
parentc6db96b19c0996c3c1afc89ac106dea7f8ff5f3b (diff)
downloadfpGUI-19fb9140056fa79aac6ccd25018bb5175ccfc0d0.tar.xz
* Finally fixed a Index out of bounds error in StringGrid. Thanks to David Emerson for finding the problem.
Diffstat (limited to 'src')
-rw-r--r--src/gui/gui_customgrid.pas16
-rw-r--r--src/gui/gui_grid.pas20
2 files changed, 26 insertions, 10 deletions
diff --git a/src/gui/gui_customgrid.pas b/src/gui/gui_customgrid.pas
index dc2c0631..b18631e1 100644
--- a/src/gui/gui_customgrid.pas
+++ b/src/gui/gui_customgrid.pas
@@ -64,6 +64,7 @@ type
function GetColumns(AIndex: integer): TfpgGridColumn; virtual;
procedure DoDeleteColumn(ACol: integer); virtual;
procedure DoSetRowCount(AValue: integer); virtual;
+ procedure DoAfterAddColumn(ACol: integer); virtual;
function DoCreateColumnClass: TfpgGridColumn; virtual;
function GetColumnCount: Integer; override;
procedure SetColumnCount(const AValue: Integer); virtual;
@@ -135,7 +136,13 @@ end;
procedure TfpgCustomGrid.DoSetRowCount(AValue: integer);
begin
- // do nothing
+ // do nothing yet
+end;
+
+procedure TfpgCustomGrid.DoAfterAddColumn(ACol: integer);
+begin
+ // do nothing yet
+ // update empty cells in descendants
end;
function TfpgCustomGrid.DoCreateColumnClass: TfpgGridColumn;
@@ -291,14 +298,17 @@ begin
end;
function TfpgCustomGrid.AddColumn(ATitle: string; AWidth: integer): TfpgGridColumn;
+var
+ i: integer;
begin
Result := DoCreateColumnClass;
Result.Title := ATitle;
Result.Width := AWidth;
Result.Backgroundcolor := clBoxcolor;
Result.TextColor := TextColor;
- FColumns.Add(Result);
-
+ i := FColumns.Add(Result);
+ DoAfterAddColumn(i); // update empty cells in descendants
+
if csUpdating in ComponentState then
Exit; //==>
diff --git a/src/gui/gui_grid.pas b/src/gui/gui_grid.pas
index 2284bec1..f694f23a 100644
--- a/src/gui/gui_grid.pas
+++ b/src/gui/gui_grid.pas
@@ -94,6 +94,7 @@ type
function GetColumns(AIndex: Integer): TfpgStringColumn; reintroduce;
procedure DoDeleteColumn(ACol: integer); override;
procedure DoSetRowCount(AValue: integer); override;
+ procedure DoAfterAddColumn(ACol: integer); override;
function DoCreateColumnClass: TfpgStringColumn; reintroduce; override;
procedure DrawCell(ARow, ACol: Integer; ARect: TfpgRect; AFlags: TfpgGridDrawState); override;
property Columns[AIndex: Integer]: TfpgStringColumn read GetColumns;
@@ -105,8 +106,8 @@ type
property Objects[ACol, ARow: Integer]: TObject read GetObjects write SetObjects;
property ColumnTitle[ACol: Integer]: string read GetColumnTitle write SetColumnTitle;
property ColumnWidth[ACol: Integer]: integer read GetColumnWidth write SetColumnWidth;
- property ColumnBackgroundColor[ACol: Integer]: TfpgColor read GetColumnBackgroundColor write SetColumnBackgroundColor;
- property ColumnTextColor[ACol: Integer]: TfpgColor read GetColumnTextColor write SetColumnTextColor;
+ property ColumnBackgroundColor;
+ property ColumnTextColor;
// property Cols[index: Integer]: TStrings read GetCols write SetCols;
// property Rows[index: Integer]: TStrings read GetRows write SetRows;
end;
@@ -404,6 +405,16 @@ begin
end;
end;
+procedure TfpgCustomStringGrid.DoAfterAddColumn(ACol: integer);
+var
+ r: integer;
+begin
+ inherited DoAfterAddColumn(ACol);
+ // initialize cells for existing rows
+ for r := 0 to RowCount-1 do
+ TfpgStringColumn(FColumns.Items[ACol]).Cells.Append('');
+end;
+
function TfpgCustomStringGrid.DoCreateColumnClass: TfpgStringColumn;
begin
Result := TfpgStringColumn.Create;
@@ -450,8 +461,6 @@ end;
function TfpgCustomStringGrid.AddColumn(ATitle: string; AWidth: integer;
AAlignment: TAlignment; ABackgroundColor: TfpgColor; ATextColor: TfpgColor): TfpgStringColumn;
-var
- r: integer;
begin
Updating;
Result := TfpgStringColumn(inherited AddColumn(ATitle, AWidth));
@@ -467,9 +476,6 @@ begin
else
Result.TextColor:= ATextColor;
- for r := 0 to RowCount-1 do
- Result.Cells.Append('');
-
if UpdateCount = 0 then
Updated; // if we called .BeginUpdate then don't clear csUpdating here
end;