Forum > LCL
Out of bounds index error
Al3:
Hey!
I am using
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---TStringGrid and wrote this function to create a new column when the user ctrl+clicks on a column:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{ Signals }procedure TForm1.listviewHeaderClick(Sender: TObject; IsColumn: Boolean; Index: Integer);var Column : TGridColumn;begin if GetKeyPressed(VK_CONTROL) = FALSE then exit; if isColumn = FALSE then exit; Column := listview.Columns.Add; Column.Title.Caption := 'Unnamed_' + listview.colCount.toString(); Column.SizePriority := 1; Column.Index := Index; Column.Alignment := taCenter;end;
However, when I set the TStringGrid's
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---AutoFillCoumns property to TRUE, so that columns expand and fill up the available space, when I attempt to create a column the program blows with an exception:
--- Quote ---Project tables raised exception class 'EGridException' with message:
Index Out of range Cell[Col=2 Row=4]
--- End quote ---
I really don't know what this has to do with out of range cells and error messages with the likes of that.
I am a bit incompetent as I am primarily a C developer that mostly only used GTK+
I came back to Lazarus after 6 years and it feels good! :)
Zvoni:
and you actually have 2 columns with 4 rows (incl. Fixed Rows/Columns)?
btw: Is it now a TStringGrid or a ListView?
Thaddy:
Yes, I was wondering about that too... We need more code, proper code.
Al3:
It is a TStringGrid
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, ExtCtrls, LCLIntf, LCLType, ValEdit, Grids; type { TForm1 } TForm1 = class(TForm) mm: TMainMenu; MenuItemFile: TMenuItem; MenuItemEdit: TMenuItem; MenuItemSearch: TMenuItem; MenuItemHelp: TMenuItem; MenuItemNew: TMenuItem; MenuItemOpen: TMenuItem; MenuItemSave: TMenuItem; MenuItemSaveAs: TMenuItem; listview: TStringGrid; procedure listviewHeaderClick(Sender: TObject; IsColumn: Boolean; Index: Integer); private public end; var Form1: TForm1; implementation function GetKeyPressed(const VKeyCode: Integer): Boolean;begin Result := GetKeyState(VKeyCode) and $80 <> 0;end; {$R *.lfm} { TForm1 } { Signals }procedure TForm1.listviewHeaderClick(Sender: TObject; IsColumn: Boolean; Index: Integer);var Column : TGridColumn;begin if GetKeyPressed(VK_CONTROL) = FALSE then exit; if isColumn = FALSE then exit; Column := listview.Columns.Add;//TGridColumn.Create(listview.Columns); Column.Title.Caption := 'Unnamed_' + listview.colCount.toString(); Column.SizePriority := 1; Column.Index := Index; Column.Alignment := taCenter; //listview.AutoFillColumns := TRUE;end; end.
Picture of how the form looks when I run the application: https://game-editor2.com/table.png
Or the entire project: https://game-editor2.com/tables.rar
There are several new concepts for me and I haven't had the time to get used to that.
Zvoni:
Ahh….. „ListView“ is the name of the TStringGrid.
Well, the only thing coming to mind has to do with the (re-) painting of the Form/Grid
Navigation
[0] Message Index
[#] Next page