问个问题,这个代码为什么报错
procedure TMainForm.Button3Click(Sender: TObject);
var
field :array of TFieldRec;
begin
field:=connection1.Meta.GetFieldList('BZWPAQSCXKZSPB');
end;
错误信息:
Incompatible types: "TFieldRec[]" and "TFieldRec[]"
可是connection1.Meta.GetFieldList('BZWPAQSCXKZSPB');的返回值就是”array of TFieldRec“,类型应该是匹配的,为什么会报类型不匹配。(”connection1.Meta.GetFieldList('BZWPAQSCXKZSPB');“这段代码正确的,可以编译通过)
var
i : integer;
field : array of TFieldRec;
begin
if ListBox1.Items = nil then exit; //如何ListBox为空 ,就不做操作
Connection1.Meta.GetTableNames(ListBox1.Items,False); //将获取的表名放入ListBox
field := Connection1.Meta.GetFieldList(ListBox1.Items[ListBox1.itemindex]); //先获取ListBox1的当前选中索引,得到表名,接着获取表的字段。
for i := low(field) to high(field) do //得到第一个字段和最后一个字段。
begin
ListBox2.Items.Add(field.Name); //将字段名赋给ListBox2
end;
end;
这段代码是论坛上的。
我根据我的需求,只取了后面的代码。
field := Connection1.Meta.GetFieldList(ListBox1.Items[ListBox1.itemindex]); //先获取ListBox1的当前选中索引,得到表名,接着获取表的字段。
for i := low(field) to high(field) do //得到第一个字段和最后一个字段。
begin
ListBox2.Items.Add(field.Name); //将字段名赋给ListBox2
end;
end;
运行到"field := Connection1.Meta.GetFieldList(ListBox1.Items[ListBox1.itemindex]); "这句代码的时候,报错:”[Incompatible types: "TFieldRec[]" and "TFieldRec[]"“,说类型不匹配,可是我查了函数的返回类型,他们的类型是匹配的,我在同事机子上运行也报这个错。
procedure TMainForm.Button2Click(Sender: TObject);
var
i : integer;
field : array of TFieldRec;
begin
field := Connection1.Meta.GetFieldList(Edit1.Text); //先获取ListBox1的当前选中索引,得到表名,接着获取表的字段。
for i := low(field) to high(field) do
begin
Memo1.Lines.Add(field.Name);
end;
end;