使用带有docolumnTitles的TValueListEditor的Delphi XE6网格索引超出范围错误DisplayOption设置为False且仅限一行

Bru*_*ong 7 delphi delphi-xe6

创建一个表单并放置一个TValueListEditor.将doColumnTitlesdisplay选项设置为False.尝试删除第一行.你会收到一个'Grid Index out of Bounds'错误.这是一头丑陋的猪,所以我在这里问一下,除了块之外是否只是尝试处理它的唯一方法?

背景:

行继承自TCustomGridvia TCustomDrawGrid(第493行VCL.grids.pas)属性getter是私有变量FCurrent.Y,其类型是来自两个值记录的值/字段.我无法找到FCurrent默认值设置的位置(因此整数默认为0).如果TValueListEditor只有一行和/或没有选择行,则不清楚存在什么值.

在任何情况下,我得到一个网格索引超出范围错误 - 可能是从 - 提出TCustomGrid- 但只有当只有一行和/或我尝试在TValueListEditorwith 的第一行删除doColumnTitles := false.删除其他行很好.无论这是否是一个错误,它似乎有些愚蠢和不一致.

TValueList编辑器构造函数是否有继承的原因RowCount := 2;

根据以下内容引发错误TValueListEditor.DeleteRow:

  try
if (Strings.Count = 0) or
   (ARow < 1) or (ARow > RowCount - FixedRows) then
  {$IF DEFINED(CLR)}
  raise EInvalidGridOperation.CreateRes(SIndexOutOfRange);
  {$ELSE}
  raise EInvalidGridOperation.CreateRes(@SIndexOutOfRange);
  {$ENDIF}

Strings.Delete(ARow - FixedRows);
  finally
    FDeleting := False;
  end;
Run Code Online (Sandbox Code Playgroud)

(参见VCL.Valedit.pas,804)

存在例外是一个问题if (ARow < 1)吗?

否则,也许它是FixedRows在以下构造函数中设置的TCustomGrid:

constructor TCustomGrid.Create(AOwner: TComponent);
Run Code Online (Sandbox Code Playgroud)

const GridStyle = [csCaptureMouse,csOpaque,csDoubleClicks,

                csNeedsBorderPaint, csPannable, csGestures];
begin
  inherited Create(AOwner);
  if NewStyleControls then
    ControlStyle := GridStyle
  else
    ControlStyle := GridStyle + [csFramed];
  FCanEditModify := True;
  FColCount := 5;
  FRowCount := 5;
  FFixedCols := 1;
  FFixedRows := 1;
Run Code Online (Sandbox Code Playgroud)

...

和VCL.grids.pas标题中的评论说"FixedRows The number of non-scrolling rows. This value must be at least one below RowCount."(第138行).

当从标题行中删除标题行时,最终会出现这些值的问题 TValueListEditor

无论如何.我的问题只是 - 这是否需要使用异常处理程序 - 还是有更优雅的方式来解决它?

这是一些基本没有安全带的代码:

unit vleDebug;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, Vcl.StdCtrls, Vcl.Grids, Vcl.ValEdit;

type
  TForm1 = class(TForm)
    vleWhoCaresNerd: TValueListEditor;
    Button1: TButton;
    BitBtn1: TBitBtn;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

    var
      Form1: TForm1;

    implementation

    {$R *.dfm}

    procedure TForm1.BitBtn1Click(Sender: TObject);
    begin    
      vleWhoCaresNerd.DeleteRow(vleWhoCaresNerd.Row);
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    var
     vGUID: TGUID;
    begin
      vleWhoCaresNerd.InsertRow('id', GUIDToString(vGUID), True);
    end;

    end.
Run Code Online (Sandbox Code Playgroud)

这是.dfm:

 object Form1: TForm1
  Left = 0
  Top = 0
  Caption = ':P'
  ClientHeight = 568
  ClientWidth = 633
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -13
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 120
  TextHeight = 16
  object Label1: TLabel
    Left = 295
    Top = 162
    Width = 242
    Height = 16
    Caption = 'Select and delete the first row if you dare.'
  end
  object Label2: TLabel
    Left = 63
    Top = 190
    Width = 393
    Height = 16
    Caption = 
      'Delete other rows if you like. Make some with  the  Add GUID But' +
      'ton.'
  end
  object vleWhoCaresNerd: TValueListEditor
    Left = 8
    Top = 8
    Width = 617
    Height = 145
    DisplayOptions = [doAutoColResize, doKeyColFixed]
    Strings.Strings = (
      'jsonrpc=2.0')
    TabOrder = 0
    ColWidths = (
      150
      461)
  end
  object Button1: TButton
    Left = 8
    Top = 159
    Width = 75
    Height = 25
    Caption = 'Add GUID'
    TabOrder = 1
    OnClick = Button1Click
  end
  object BitBtn1: TBitBtn
    Left = 550
    Top = 159
    Width = 75
    Height = 25
    Caption = 'bbDelete'
    TabOrder = 2
    OnClick = BitBtn1Click
  end
end
Run Code Online (Sandbox Code Playgroud)