S
sileo
Unregistered / Unconfirmed
GUEST, unregistred user!
请看下面的注释部分. 谢谢!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
Pfld = ^fld;
fld = Record
S1: string;
S2: string;
F1: double;
F2: double;
I1: Integer;
I2: Integer;
D1: TDateTime;
D2: TDateTime;
//...
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Tfld : pfld;
function Set_FLds( fldName:string
fldValue: variant ):string;
implementation
{$R *.DFM}
function Set_FLds( fldName:string
fldValue: variant ):string;
begin
New(Tfld);
//以下方法太笨了, 有没有好的办法?
//能不能自动找记录的名称, 并赋值?
//
if fldName = 'S1' then
begin
Tfld.S1 := fldValue;
exit;
end;
if fldName = 'S2' then
begin
Tfld.S2 := fldValue;
exit;
end;
if fldName = 'F1' then
begin
Tfld.F1 := fldValue;
exit;
end;
if fldName = 'F2' then
begin
Tfld^.F2 := fldValue;
exit;
end;
//....
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Set_Flds( 'S1','0000123');
showmessage(Tfld^.S1);
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
Pfld = ^fld;
fld = Record
S1: string;
S2: string;
F1: double;
F2: double;
I1: Integer;
I2: Integer;
D1: TDateTime;
D2: TDateTime;
//...
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Tfld : pfld;
function Set_FLds( fldName:string
fldValue: variant ):string;
implementation
{$R *.DFM}
function Set_FLds( fldName:string
fldValue: variant ):string;
begin
New(Tfld);
//以下方法太笨了, 有没有好的办法?
//能不能自动找记录的名称, 并赋值?
//
if fldName = 'S1' then
begin
Tfld.S1 := fldValue;
exit;
end;
if fldName = 'S2' then
begin
Tfld.S2 := fldValue;
exit;
end;
if fldName = 'F1' then
begin
Tfld.F1 := fldValue;
exit;
end;
if fldName = 'F2' then
begin
Tfld^.F2 := fldValue;
exit;
end;
//....
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Set_Flds( 'S1','0000123');
showmessage(Tfld^.S1);
end;
end.