<pre><pre class="text">
unit Unit1;
interface
uses
Windows, Classes, Forms, Dialogs, Db, DBTables, Controls,
StdCtrls ;
type
TForm1 = class(TForm)
Button1: TButton;
Table1: TTable;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
type TableRecord = record
CustNo:integer;
Company:String;
Addr1:string;
Addr2:String;
City:String;
end;
var Customer:array of TableRecord;
begin
table1.DatabaseName:='DBDEMOS';
table1.tablename:='customer.db';
table1.DisableControls;
table1.open;
SetLength(Customer, table1.RecordCount);
while not table1.eofdo
begin
Customer[table1.recno-1].CustNo:=table1.fieldbyname('custno')
.AsInteger;
Customer[table1.recno-1].Company:=table1.fieldbyname('Company
').AsString;
Customer[table1.recno-1].Addr1:=table1.fieldbyname('Addr1').A
sString;
Customer[table1.recno-1].Addr2:=table1.fieldbyname('Addr2').A
sString;
Customer[table1.recno-1].City:=table1.fieldbyname('City').AsS
tring;
table1.next;
end;
table1.Close;
showmessage(customer[1].City);//返回第二记录的城市名称
end;
end.
</font></pre>