菜鸟枚举问题
implementation
uses Math;
type
MyFont=(st,ls,ht);
var
ft:MyFont;
{$R *.dfm}
function ffont(fft:MyFont):string;
begin
case fft of
st:Result:= '宋体';
ls:Result:= '隶书';
ht:Result:= '黑体';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
If Button1.Caption = '宋体' then
begin
//ft:= st;
Edit1.Font.Name:= ffont(st);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
If Button2.Caption = '隶书' then
begin
//ft:= ls;
Edit1.Font.Name:= ffont(ls);
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
If Button3.Caption = '黑体' then
begin
//ft:= ht;
Edit1.Font.Name:= ffont(ht);
end;
end;
end.
uses Math;
type
MyFont=(st,ls,ht);
{var
ft:MyFont;}
{$R *.dfm}
function ffont(fft:MyFont):string;
begin
case fft of
st:Result:= '宋体';
ls:Result:= '隶书';
ht:Result:= '黑体';
end;
end;
uses
Math;
type
MyFont = (st, ls, ht);
function FFont(fft: MyFont): string;
begin
case fft of
st: Result := '宋体';
ls: Result := '隶体';
Ht: Result := '黑体';
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(FFont(Ht));
end;
这样用得很好的啊!不用另外声明MyFont变量类型即可调用!