请问怎么把表内容转化为数组?谢谢!(200分)

  • 主题发起人 主题发起人 stock
  • 开始时间 开始时间
S

stock

Unregistered / Unconfirmed
GUEST, unregistred user!
有表A:
TYPE NAME
001 001001001
002 222222222
003 300300300

想把表A的内容转化为二维数组:
TYPENAME[0,0]:='001' TYPENAME[0,1]:='001001001'
TYPENAME[1,0]:='001' TYPENAME[1,1]:='001001001'
TYPENAME[2,0]:='001' TYPENAME[2,1]:='001001001'


程序如下:

var type_name: array of array of string;
count:integer;
begin
query.close;
query.sql.text:='select * from tableA where 條件';
query.open;
SetLength(type_name, query.recoardcount-1, query.fields.count-1);


??????

end;

请问在问号处应该怎么为该数组赋值?谢谢!
 
>TYPENAME[0,0]:='001' TYPENAME[0,1]:='001001001'
>TYPENAME[1,0]:='001' TYPENAME[1,1]:='001001001'
>TYPENAME[2,0]:='001' TYPENAME[2,1]:='001001001'

应该是如下吧:
TYPENAME[0,0]:='001' TYPENAME[0,1]:='001001001'
TYPENAME[1,0]:='002' TYPENAME[1,1]:='222222222'
TYPENAME[2,0]:='003' TYPENAME[2,1]:='300300300'
如果是的话,可以这样做:

var
type_name : array of array of string;
FieldCnt, i, j : integer;
begin
query.close;
query.sql.text:='select * from tableA where 條件';
query.open;
FieldCnt := query.FieldCount;
SetLength(type_name, query.recoardcount-1, FieldCnt-1);

i := 0;
with query do
begin

while not Eof do
begin
for j := 0 to FieldCnt-1 do
type_name[i, j] := Fields[j].AsString;
Next;
Inc(i);
end;

Close;
end;
end;
 
请问INC(i)是什么意思?
 
就是i+1 的意思.
 
netkk的解决办法运行时候出现错误
 
这样做试试
var type_name: array of array of string;
i,j:integer;
begin
query.close;
query.sql.text:='select * from tableA where 條件';
query.open;
if query.recordcount>0 then
begin
SetLength(type_name, query.recordcount-1, query.fields.count-1);
for i:=0 to query.recordcount-1 do
begin
for j := 0 to query.fields.count-1 do
type_name[i, j]:=query.fields[j].AsString;
end;
end;
 
试了一下,如下可以了:
procedure TForm1.Button1Click(Sender: TObject);
var
type_name : array of array of string;
FieldCnt, i, j : integer;
begin
query.close;
query.sql.text:='select * from tableA where 條件';
query.open;
FieldCnt := query.FieldCount;

if query.recordcount>0 then
begin

SetLength(type_name, query.RecordCount, FieldCnt); // --------此处定义数组

for i:=0 to query.recordcount-1 do
begin
for j := 0 to query.fields.count-1 do
begin
type_name[i, j]:=query.fields[j].AsString;
ShowMessage(query.fields[j].AsString); //----------循环显示出来了
end;
query.Next; //----------------下一条记录
end;
end;
end;
 
这样做试试(改一下楼上兄台的代码)
var type_name: array of array of string;
i,j:integer;
begin
query.close;
query.sql.text:='select * from tableA where 條件';
query.open;
if query.recordcount>0 then
begin
SetLength(type_name, query.recordcount, query.fields.count);
for i:=0 to query.recordcount-1 do
begin
for j := 0 to query.fields.count-1 do
type_name[i, j]:=query.fields[j].AsString;
end;
end;
 
jrq的办法解决问题,谢谢!!!
 
后退
顶部