implementationuses 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.
--------------
为什么不能去掉
var
ft:MyFont;
去掉就会提示错误。一定要指定一个枚举类型的变量吗,是不是语法就是这么规定的?
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.
--------------
为什么不能去掉
var
ft:MyFont;
去掉就会提示错误。一定要指定一个枚举类型的变量吗,是不是语法就是这么规定的?
是有地方使用这个变量了
你去掉var ft:MyFont;看哪儿报错就知道问题了
哥 你那個函數是MyFont 類型 所以 哥……必須 的
是有地方使用这个变量了
你去掉var ft:MyFont;看哪儿报错就知道问题了
报错的那一行是function ffont(fft:MyFont):string;并没有使用ft这个枚举变量
是有地方使用这个变量了
你去掉var ft:MyFont;看哪儿报错就知道问题了
报错的那一行是function ffont(fft:MyFont):string;并没有使用ft这个枚举变量不可能出错, 你新建一个工程, 用这几句试试
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变量类型即可调用!
ft:MyFont; //声明变量
begin
ft:=st; //赋值
ShowMessage(FFont(Ft)); //调用MyFont类型变量Ft
end;