[SOLVED] Error "List index (0) out of bounds" while opening form in IDE on Linux lazarus / 10-Designer ---------------------------------------------------------------------- Unvictis · 2017-02-08 09:46 Hi, guys! If i open my project in IDE on Windows (XP, 7, 10 - any) its opens normally. If i open same project in Lazarus on my Ubuntu Mate 16.04 x64 desktop, i see error: "List index (0) out of bounds". Empirically, I found out that this problem occurs when the IDE tries to open the "fDevEditor" in my application. Nothing strange or unusual in the code and file "fDevEditor.lfm" I have not found. Tell me how to solve this problem? IDE (Windows): Lazarus 1.6.2 (x86) IDE (Ubuntu 16.04 x64): Lazarus 1.6+dfsg-1 (x86_64-linux-gtk2) [from standart Ubuntu repo] PS: None of the project files I edited on a straight line - only through IDE. File fdeveditor.pas: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit fDevEditor; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,  StdCtrls, DbCtrls, DBGrids, LCLType, uCommon, dOrder; type   { TfmDevEditor }   TfmDevEditor = class(TForm)    btCancel: TButton;    btOk: TButton;  btAddDevice: TButton;    btDeleteDevice: TButton;    edNewDevice: TEdit;    dgDevices: TDBGrid;    lbNewDevice: TLabel;    plContents: TPanel;    plButtonContainer: TPanel;    procedure btAddDeviceClick(Sender: TObject);    procedure btDeleteDeviceClick(Sender: TObject);    procedure edNewDeviceChange(Sender: TObject);    procedure edNewDeviceKeyDown(Sender: TObject; var Key: Word;      Shift: TShiftState);    procedure FormShow(Sender: TObject);  private    { private declarations }  public    { public declarations }  end; var  fmDevEditor: TfmDevEditor; implementation {$R *.lfm} { TfmDevEditor } procedure TfmDevEditor.FormShow(Sender: TObject);begin  edNewDevice.Clear;  btAddDevice.Enabled := False;  edNewDevice.SetFocus;end; procedure TfmDevEditor.edNewDeviceChange(Sender: TObject);begin  btAddDevice.Enabled := (Length(edNewDevice.Text) >= 2);end; procedure TfmDevEditor.edNewDeviceKeyDown(Sender: TObject; var Key: Word;  Shift: TShiftState);begin  // Если нажата клавиша "Enter" нажать кнопку "Добавить"  if (Key = VK_RETURN) and btAddDevice.Enabled then  btAddDeviceClick(Sender);end; procedure TfmDevEditor.btAddDeviceClick(Sender: TObject);begin  with dmOrder.sqDevice do    begin      Insert;      FieldByName('CREATOR').AsInteger := CurrentUserID;      FieldByName('EDITOR').AsInteger := CurrentUserID;      FieldByName('DEVICE').AsString := edNewDevice.Text;      Post;    end;   edNewDevice.Clear;end; procedure TfmDevEditor.btDeleteDeviceClick(Sender: TObject);begin  with dmOrder.sqDevice do    if MessageDlg(cDlgConfirmation, Format(cDlgDeviceDelConfirm,      [FieldByName('DEVICE').AsString]), mtConfirmation, mbYesNo, 0) = mrYes then        Delete;end; end.  File fdeveditor.lfm: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i object fmDevEditor: TfmDevEditor  Left = 324  Height = 307  Top = 134  Width = 281  BorderStyle = bsDialog  BorderWidth = 4  Caption = 'Типы устройств'  ClientHeight = 307  ClientWidth = 281  OnShow = FormShow  Position = poOwnerFormCenter  LCLVersion = '1.6.2.0'  object plButtonContainer: TPanel    Left = 4    Height = 25    Top = 278    Width = 273    Align = alBottom    AutoSize = True    BorderSpacing.Top = 4    BevelOuter = bvNone    ChildSizing.HorizontalSpacing = 4    ClientHeight = 25    ClientWidth = 273    TabOrder = 1    object btCancel: TButton      Left = 198    Height = 25      Top = 0      Width = 75      Align = alRight      Cancel = True      Caption = 'Отмена'      ModalResult = 2      TabOrder = 1    end    object btOk: TButton      Left = 119      Height = 25      Top = 0      Width = 75      Align = alRight      Caption = 'OK'      Default = True      ModalResult = 1      TabOrder = 0    end  end  object plContents: TPanel    Left = 4    Height = 270    Top = 4    Width = 273    Align = alClient    AutoSize = True  BevelOuter = bvNone    BorderWidth = 4    ClientHeight = 270    ClientWidth = 273    TabOrder = 0    object lbNewDevice: TLabel      AnchorSideLeft.Control = dgDevices      AnchorSideTop.Control = plContents      Left = 4      Height = 15      Top = 4      Width = 145      BorderSpacing.Bottom = 4      Caption = 'Новый тип оборудования:'      ParentColor = False    end    object btAddDevice: TButton      AnchorSideTop.Side = asrCenter      AnchorSideRight.Control = plContents      AnchorSideRight.Side = asrBottom      Left = 194      Height = 25      Top = 22      Width = 75      Anchors = [akTop, akRight]      BorderSpacing.Bottom = 8      Caption = 'Добавить'      Enabled = False      OnClick = btAddDeviceClick      TabOrder = 1    end    object btDeleteDevice: TButton      AnchorSideTop.Control = btAddDevice      AnchorSideTop.Side = asrBottom      AnchorSideRight.Control = plContents      AnchorSideRight.Side = asrBottom      Left = 194      Height = 25      Top = 55      Width = 75      Anchors = [akTop, akRight]      BorderSpacing.Bottom = 8      Caption = 'Удалить'      OnClick = btDeleteDeviceClick      TabOrder = 2    end    object dgDevices: TDBGrid      AnchorSideLeft.Control = plContents      AnchorSideTop.Side = asrBottom      AnchorSideRight.Side = asrBottom    AnchorSideBottom.Control = plContents      AnchorSideBottom.Side = asrBottom      Left = 4      Height = 212      Top = 54      Width = 182      Anchors = [akTop, akRight]      AutoEdit = False      AutoFillColumns = True      Color = clWindow      Columns = <            item          Title.Caption = 'Устройство'          Width = 161        FieldName = 'DEVICE'        end>      DataSource = dmOrder.dsDevice      FixedCols = 0      Options = [dgColumnResize, dgColumnMove, dgTabs, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgTruncCellHints]      Scrollbars = ssVertical      TabOrder = 3    end    object edNewDevice: TEdit      AnchorSideLeft.Control = plContents      AnchorSideTop.Control = lbNewDevice      AnchorSideTop.Side = asrBottom      AnchorSideRight.Control = btAddDevice      Left = 4      Height = 23    Top = 23      Width = 182      Anchors = [akTop, akRight]      BorderSpacing.Right = 8      BorderSpacing.Bottom = 8      MaxLength = 50      OnChange = edNewDeviceChange      OnKeyDown = edNewDeviceKeyDown      TabOrder = 0    end  endend ---------------------------------------------------------------------- howardpc · 2017-02-08 14:12 Diagnosing the cause requires you to publish your project (Project->Publish Project...) and zip the published folder with some actual or dummy data. The unit and .lfm you show depend on other unseen code and data. ---------------------------------------------------------------------- Unvictis · 2017-02-08 14:16 Full project source. ---------------------------------------------------------------------- Handoko · 2017-02-08 14:22 Tested and confirmed. I got similar error. ---------------------------------------------------------------------- howardpc · 2017-02-08 14:30 I get a different exception: EIBDatabaseError   icConnection:DoInternalConnect: -cannot attach to password database ---------------------------------------------------------------------- Handoko · 2017-02-08 14:33 Try to open fDevEditor.pas and then switch to the form view. ---------------------------------------------------------------------- Unvictis · 2017-02-08 14:56 Quote from: howardpc on February 08, 2017, 03:30:36 pmI get a different exception: EIBDatabaseError   icConnection:DoInternalConnect: -cannot attach to password database I do not include database with source (size > 1 MB). ---------------------------------------------------------------------- Handoko · 2017-02-08 16:48 Hi Unvictis. After some testings, I found the culprit. I can't explain why, but I have solution to fix the error. Use your text editor to open fDevEditor.pas and add dgIndicator in the line 125. So it will become: QuoteOptions = [dgIndicator, dgColumnResize, dgColumnMove, dgTabs, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgTruncCellHints] I have tested several times. Without dgIndicator the form will cause error when opening. But if dgIndicator is added, problem solved. ---------------------------------------------------------------------- Unvictis · 2017-02-08 16:55 Quote from: Handoko on February 08, 2017, 05:48:54 pmHi Unvictis. After some testings, I found the culprit. I can't explain why, but I have solution to fix the error. Use your text editor to open fDevEditor.pas and add dgIndicator in the line 125. So it will become: QuoteOptions = [dgIndicator, dgColumnResize, dgColumnMove, dgTabs, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgTruncCellHints] I have tested several times. Without dgIndicator the form will cause error when opening. But if dgIndicator is added, problem solved. Thank you! I test it tomorrow, on work! ---------------------------------------------------------------------- Unvictis · 2017-02-09 13:01 Quote from: Handoko on February 08, 2017, 05:48:54 pmHi Unvictis. After some testings, I found the culprit. I can't explain why, but I have solution to fix the error. Use your text editor to open fDevEditor.pas and add dgIndicator in the line 125. So it will become: QuoteOptions = [dgIndicator, dgColumnResize, dgColumnMove, dgTabs, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgTruncCellHints] I have tested several times. Without dgIndicator the form will cause error when opening. But if dgIndicator is added, problem solved. Again, thank you very much for your time! After your actions proposed by the error message no longer appears. However, apparently this is a bug, and I think it should be sent to Lazarus bugtracker. ---------------------------------------------------------------------- Handoko · 2017-02-09 15:21 If you have time, please report it to the bugtracker: http://bugs.freepascal.org/my_view_page.php I'm not familiar with TDBGrid so better not me to submit the bug. ---------------------------------------------------------------------- Unvictis · 2017-02-12 10:33 OK. I post this error on bugtracker. ---------------------------------------------------------------------- Handoko · 2017-02-12 12:35 Thank you. I saw it's now in the bugtracker: http://bugs.freepascal.org/view.php?id=31380 ---------------------------------------------------------------------- JuhaManninen · 2017-02-12 12:44 Quote from: Handoko on February 12, 2017, 01:35:42 pmI saw it's now in the bugtracker: http://bugs.freepascal.org/view.php?id=31380 See also the comments / questions there. A backtrace would also be helpful. Please pay attention to the quality of bug reports. ---------------------------------------------------------------------- Unvictis · 2017-02-12 13:05 Quote from: Handoko on February 12, 2017, 01:35:42 pmThank you. I saw it's now in the bugtracker: http://bugs.freepascal.org/view.php?id=31380 Thank you! ---------------------------------------------------------------------- JuhaManninen · 2017-09-22 13:42 Quote from: Unvictis on February 08, 2017, 10:46:48 amHi, guys! If i open my project in IDE on Windows (XP, 7, 10 - any) its opens normally. If i open same project in Lazarus on my Ubuntu Mate 16.04 x64 desktop, i see error: "List index (0) out of bounds". @Unvictis, are you still reading this forum? I can reproduce the issue :   http://bugs.freepascal.org/view.php?id=31380 and I debugged it for a long time. See my note there. To reproduce on different platforms you should build the IDE with all possible debug flags, including -gt or -gtt. Even then it may not reproduce everywhere. Linux may be better for debugging such issues than WinXP. I hope either my workaround or a proper fix by Jesus Reyes will be merged to Lazarus 1.8. Quote from: Handoko on February 08, 2017, 05:48:54 pmAfter some testings, I found the culprit. I can't explain why, but I have solution to fix the error. Use your text editor to open fDevEditor.pas and add dgIndicator in the line 125. So it will become: QuoteOptions = [dgIndicator, dgColumnResize, dgColumnMove, dgTabs, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit, dgTruncCellHints]Did you figure it out without studying the code? Quite amazing! The reason can be seen in function TCustomDBGrid.UpdateGridCounts. With dgIndicator both column count and row count are incremented -> the columns are not cleared later. This forum thread is marked as [SOLVED]. It is not solved yet but now we are closer. ---------------------------------------------------------------------- JuhaManninen · 2017-09-22 22:04 I fixed it myself. Please test.