unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, DB, ADODB, Grids, DBGrids;type TForm1 = class(TForm) DataSource1: TDataSource; ADOTable1: TADOTable; BitBtn1: TBitBtn; DBGrid1: TDBGrid; procedure BitBtn1Click(Sender: TObject); private fUNCTION GETFNAME(S:STRING):STRING; fUNCTION GETFNAME2(S:STRING):STRING; { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm} function TForm1.GETFNAME(S: STRING): STRING; var i:integer; begin for i :=0 to ADOTable1.FieldCount-1 do begin if ADOTable1.Fields[i].DisplayLabel=S then Result:=ADOTable1.Fields[i].FieldName; end; //For end;function TForm1.GETFNAME2(S: STRING): STRING; begin Result:=ADOTable1.Fieldbyname(s).DisplayName; end; procedure TForm1.BitBtn1Click(Sender: TObject); begin with ADOTable1 do begin Fields[0].DisplayLabel:='A'; Fields[1].displayLabel:='B'; Fields[2].DisplayLabel:='C'; ShowMessage(GETFNAME('A')); ShowMessage(GETFNAME2('field1')); end; //withend;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, DB, ADODB, Grids, DBGrids;type
TForm1 = class(TForm)
DataSource1: TDataSource;
ADOTable1: TADOTable;
BitBtn1: TBitBtn;
DBGrid1: TDBGrid;
procedure BitBtn1Click(Sender: TObject);
private
fUNCTION GETFNAME(S:STRING):STRING;
fUNCTION GETFNAME2(S:STRING):STRING;
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
function TForm1.GETFNAME(S: STRING): STRING;
var i:integer;
begin
for i :=0 to ADOTable1.FieldCount-1 do begin
if ADOTable1.Fields[i].DisplayLabel=S then
Result:=ADOTable1.Fields[i].FieldName;
end; //For
end;function TForm1.GETFNAME2(S: STRING): STRING;
begin
Result:=ADOTable1.Fieldbyname(s).DisplayName;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
with ADOTable1 do begin
Fields[0].DisplayLabel:='A';
Fields[1].displayLabel:='B';
Fields[2].DisplayLabel:='C';
ShowMessage(GETFNAME('A'));
ShowMessage(GETFNAME2('field1'));
end; //withend;end.