创建表单并放置TValueListEditor
。将doColumnTitles
显示选项设置为False。尝试删除第一行。您将收到'Grid Index out of Bounds'
错误。这是一头丑陋的小猪,所以我在这里问一下,除了块之外是否只是尝试处理它?</ p>
背景:
行从TCustomGrid
通过TCustomDrawGrid
继承(第493行VCL.grids.pas)属性getter是私有变量FCurrent.Y
,其类型是来自a的值/字段两个价值记录。我无法找到默认设置FCurrent
值的位置(因此整数默认为0)。如果TValueListEditor
只有一行和/或没有选择行,则不清楚存在哪些值。
在任何情况下,我都会得到一个网格索引超出范围错误 - 可能是从TCustomGrid
引出的 - 但只有当只有一行和/或我在{{的第一行尝试删除时1}}与TValueListEditor
。删除其他行很好。无论这是否是一个错误,它似乎有些愚蠢和不一致。
doColumnTitles := false
编辑器构造函数是否继承了TValueList
?
RowCount := 2;
根据以下内容引发错误:
TValueListEditor.DeleteRow
(见804的VCL.Valedit.pas)
是否存在异常 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;
的问题?
否则,也许是if (ARow < 1)
的构造函数中设置了FixedRows
:
TCustomGrid
常量 GridStyle = [csCaptureMouse,csOpaque,csDoubleClicks,
constructor TCustomGrid.Create(AOwner: TComponent);
...
以及VCL.grids.pas标题中的评论说 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;
(第138行)。
当从"FixedRows The number of non-scrolling rows. This value must be at least one below RowCount."
反正。我的问题只是 - 这是否需要使用异常处理程序 - 还是有更优雅的方式来解决它?
以下是一些基本没有安全带的代码:
TValueListEditor
这里是.dfm:
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.