是在运行时出的错,首次运行没错,第二次,第三次运行就出错了。
现在原来的错误没有了,又出现List index out of bounds (-1)这种错误了,
运行后就弹出对话框,显示List index out of bounds (-1),停止运行后,
稍微一动光标就会弹出这种对话框,不知道怎么解决!!!
procedure TMainForm.BizFormCreate(Sender: TObject);
var
NewTreeNode : TTreeNode;
lBizField: TBizField;
lStream: TMemoryStream;
KeyField:String;
DisplayField:String;
tabelname:String;
datatype:String;
begin
lBizField := TBizDataSet(DataSetBroker1.DataSet).FindBizField('sid');
if lBizField <> nil then
begin
lBizField.LookupDef.Kind := TLookupKind.lkEnumValues;
newtreenode:=TreeView1.Items.add(nil,'序号');
KeyField:=lBizField.LookupDef.KeyField;
DisplayField:=lBizField.LookupDef.DisplayField;
lStream := TMemoryStream.Create;
try
DataSetBroker1.DataSet.Open;
DataSetBroker1.DataSet.SaveToStream(lStream, TDataPacketFormat.dfXML);
lStream.Position := 0;
lBizField.LookupDef.Values.LoadFromStream(lStream);
TBizDataSet(DataSetBroker1.DataSet).LayoutChange;
finally
lStream.Free;
if(DataSetBroker1.DataSet.FieldByName('sid')<>'')then
begin
Treeview1.Items.AddChild(newtreenode,lBizField.LookupDef.KeyField);
Treeview1.Items.AddChild(newtreenode,lBizField.LookupDef.DisplayField);
Treeview1.Items.AddChild(newtreenode,lBizField.URL); //lBizField.URL
Treeview1.Items.AddChild(newtreenode,lBizField.FullID); // lBizField.FullID
Treeview1.Items.AddChild(newtreenode,tsqldataset(datasetbroker1.DataSet).BizFields[0].Origin.BizTableDef.DisplayName);
Treeview1.Items.AddChild(newtreenode,tbizdataset(datasetbroker1.DataSet).BizFields('sid').GetType.ToString());
if datasetbroker1.DataSet.Fields[0].DataType=business.Data.TFieldType.ftString then
datatype:='String';
edit1.Text:=datatype;
end;
end;
end
else
//FindBizFieldError;
end;
end.这是代码 |