各个控件的初始值都没改的,SimpleDataSet1 里也没有静态字段。源程序如下: with SimpleDataSet1 do
begin
DataSet.CommandText := 'SELECT int_compid, int_company_grade FROM gl_company';
Close; // 增加计算字段 // 增加查找字段
field := TStringField.Create(self);
field.FieldName := 'lookup_GradeName';
field.Name := Name + field.FieldName;
field.FieldKind := fkLookUp;
field.KeyFields := 'int_company_grade';
field.LookupDataSet := SimpleDataSet2;
field.LookupKeyFields := 'int_ID';
field.LookupResultField := 'vc_name';
field.DataSet := SimpleDataSet1.DataSet;
//Fields.Add(field); Open;
//ShowMessage(IntToStr(Fields.Count)); // 添加到DBGrid上
DBGrid1.Columns.Clear;
for i := 0 to Fields.Count - 1 do
begin
col := DBGrid1.Columns.Add;
col.FieldName := Fields[i].FieldName; end;
end;运行到 Open语句时会出错:---------------------------
Debugger Exception Notification
---------------------------
Project demotest.exe raised exception class EDatabaseError with message 'InternalDataSet: Field 'lookup_GradeName' cannot be a calculated or lookup field'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
如果是用 Fields.Add(field); 语句时,则会出现另一个错误:---------------------------
Debugger Exception Notification
---------------------------
Project demotest.exe raised exception class EDatabaseError with message 'Cannot perform this operation on a closed dataset'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
begin
DataSet.CommandText := 'SELECT int_compid, int_company_grade FROM gl_company';
Close; // 增加计算字段 // 增加查找字段
field := TStringField.Create(self);
field.FieldName := 'lookup_GradeName';
field.Name := Name + field.FieldName;
field.FieldKind := fkLookUp;
field.KeyFields := 'int_company_grade';
field.LookupDataSet := SimpleDataSet2;
field.LookupKeyFields := 'int_ID';
field.LookupResultField := 'vc_name';
field.DataSet := SimpleDataSet1.DataSet;
//Fields.Add(field); Open;
//ShowMessage(IntToStr(Fields.Count)); // 添加到DBGrid上
DBGrid1.Columns.Clear;
for i := 0 to Fields.Count - 1 do
begin
col := DBGrid1.Columns.Add;
col.FieldName := Fields[i].FieldName; end;
end;运行到 Open语句时会出错:---------------------------
Debugger Exception Notification
---------------------------
Project demotest.exe raised exception class EDatabaseError with message 'InternalDataSet: Field 'lookup_GradeName' cannot be a calculated or lookup field'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
如果是用 Fields.Add(field); 语句时,则会出现另一个错误:---------------------------
Debugger Exception Notification
---------------------------
Project demotest.exe raised exception class EDatabaseError with message 'Cannot perform this operation on a closed dataset'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
---------------------------
Debugger Exception Notification
---------------------------
Project demotest.exe raised exception class EDatabaseError with message 'No fields defined. Cannot create dataset'. Process stopped. Use Step or Run to continue.
---------------------------
OK Help
---------------------------
with SimpleDataSet1 do
begin
DataSet.CommandText := 'SELECT gl_company.int_compid, gl_company.int_company_grade FROM '+
'gl_company a LEFT JOIN Table2 b on a.int_company_grade=b.int_company_grade ';
Open;
end;
begin
Close;//换个位置 DataSet.CommandText := 'SELECT int_compid, int_company_grade FROM gl_company';
//Close; // 增加计算字段 // 增加查找字段
field := TStringField.Create(self);
field.FieldName := 'lookup_GradeName';
field.Name := Name + field.FieldName;
field.FieldKind := fkLookUp;
field.KeyFields := 'int_company_grade';
field.LookupDataSet := SimpleDataSet2;
field.LookupKeyFields := 'int_ID';
field.LookupResultField := 'vc_name';
field.DataSet := SimpleDataSet1.DataSet;
//Fields.Add(field); Open;
//ShowMessage(IntToStr(Fields.Count)); // 添加到DBGrid上
DBGrid1.Columns.Clear;
for i := 0 to Fields.Count - 1 do
begin
col := DBGrid1.Columns.Add;
col.FieldName := Fields[i].FieldName; end;
end;运行到 Open语句时会出错:
----
这段代码中的
SimpleDataSet1和SimpleDataSet2是什么呀。
是数据集吗?怎么没有DataSet属性?