Undeclared identifier: 'YearOf'问题
程序如下:
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Mask, StdCtrls;
type
TForm1 = class(TForm)
lblName: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
edtName: TEdit;
edtScore1: TEdit;
edtScore2: TEdit;
meIDCard: TMaskEdit;
mePhone: TMaskEdit;
btnGetInfo: TButton;
lblBirthday: TLabel;
lblSex: TLabel;
lblAge: TLabel;
lblScore: TLabel;
procedure edtScore1KeyPress(Sender: TObject; var Key: Char);
procedure edtScore2KeyPress(Sender: TObject; var Key: Char);
procedure btnGetInfoClick(Sender: TObject);
private
{ Private declarations }
function ExtractBirthday(const IDCard:string):TDate;
function ExtractSex(const IDCard:string):Boolean;
function CalcScore(const S1,S2:string):Real;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.ExtractBirthday (const IDCard:string):TDate;
var
Str:string;
Len:Integer;
begin
Str:=Trim(IDCard);
Len:=Length(IDCard);
case Len of
15:Str:=Copy(Str,7,2)+'-'+Copy(Str,9,2)+'-'+Copy(Str,11,2);
18:Str:=Copy(Str,7,4)+'-'+Copy(Str,11,2)+'-'+Copy(Str,13,2);
end;
Result:=StrToDate(Str);
end;
function TForm1.ExtractSex (const IDCard:string):Boolean;
var
Str:string;
Len:Integer;
begin
Result:=False;
Str:=Trim(IDCard);
Len:=Length(Str);
case Len of
15:Result:=StrToInt(Str[15]) mod 2<>0;
18:Result:=StrToInt(Str[17]) mod 2<>0;
end;
end;
function TForm1.CalcScore (const S1,S2:string):Real;
begin
Result:=StrToInt(S1)*0.6+StrToInt(S2)*0.4;
end;
procedure TForm1.edtScore1KeyPress(Sender: TObject; var Key: Char);
begin
if(key<#8)or((key>#8) and (key<#46)) or ((key>#46)and(key<#48)) or (key>#57) then
Key:=#0;
end;
procedure TForm1.edtScore2KeyPress(Sender: TObject; var Key: Char);
begin
if(key<#8)or((key>#8) and (key<#46)) or ((key>#46)and(key<#48)) or (key>#57) then
Key:=#0;
end;
procedure TForm1.btnGetInfoClick(Sender: TObject);
var
Birthday:TDate;
begin
Birthday:=ExtractBirthday(meIDCard.Text);
if Length(Trim(meIDCard.Text))>0 then begin
lblBirthday.Caption:=Format('出生日期:%d年%d月%d日',[YearOf(Birthday),MonthOf(Birthday),DayOf(Birthday)]);
if ExtractSex(meIDCard.Text) then
lblSex.Caption:='性别:男'
else
lblSex.Caption:='性别:女';
end;
lblAge.Caption:='年龄:'+IntToStr(YearOf(Now)-YearOf(Birthday));
lblScore.Caption:='考试成绩:'+Format('%5.1f',[CalcScore(edtScore1.Text,edtScore2.Text)])'
end;
end.
运行后提示错误为:
[Error] MainForm.pas(93): Undeclared identifier: 'YearOf'
[Error] MainForm.pas(93): Undeclared identifier: 'MonthOf'
[Error] MainForm.pas(93): Undeclared identifier: 'DayOf'
[Error] MainForm.pas(100): Unterminated string
[Fatal Error] Project1.dpr(5): Could not compile used unit '..\chenyue\Exa04-14\MainForm.pas'