unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormClick(Sender: TObject);
private
Persons:array[1..4] of TPerson;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Persons[1]:TBoss.Create('赵晓光',800.0);
Persons[2]:TEmployee.Create('钱明',400.0,3.0,150);
Persons[3]:TPieceWorker.Create('孙正',2.5,200);
Persons[4]:THourlyWorker.Create('李大',13.75,50.0);
end;procedure TForm1.FormDestory(Sender:TObject);
var
i:Integer;
begin
for i:=1 to 4 do begin
Persons[i].Free;
Persons[i]:=nil;
end;
end;procedure TForm1.FormClick(Sender: TObject);
var
i:Integer;
begin
for i:=1 to 4 do
ListBox1.Items.Add(Format('%8s %10.2f',[Person[i].Name,Person[i].Earnings]));
end;end.
unit untPerson;interfacetype
TPerson=class
private
FName:string;
public
constructor Create(NameValue:string);
function Earnings:Real;virtual;abstract;
property Name:string read FName write FName;
end;implementationconstructor TPerson.Create(NameValue:string);
begin
FName:=NameValue;
end;
end.type
TBoss=class(TPerson)
private
FSalary:Real;
public
constructor Create(NameValue:string;SalaryValue:Real);
function Earnings:Real;override;
property WeeklySalary:Real read FSalary write FSalary;
end;
implementationuses
SysUtils;constructor Create(NameValue:string;SalaryValue:Real);
begin
inherited Create(NameValue);
WeeklySalary:=SalaryValue;
end;function TBoss.Earnings:Real;
begin
Result:=WeeklySalary;
end;
end.
unit untPieceWork;interfaceuses
untPerson;type
TPieceWorker=class(TPerson)
private
FQuantity:Integer;
FWagePerPiece:Real;
public
constructor Create(NameValue:string;WagePerPieceValue:Real;QuantityValue:Integer);
function Earnings:Real;override;
property WagePerPiece:Real read FWagePerPiece write FWagePerPiece;
property Quantity:Real read FQuantity write FQuantity;
end;implementationconstructor Create(NameValue:string;WagePerPieceValue:Real;QuantityValue:Integer);
begin
inherited Create(NameValue);
WagePerPiece:=WagePerPieceValue;
Quantity:=QuantityValue;
end;function TPieceWorker.Earnings:Real;
begin
Result:=WagePerPiece*Quantity;
end;
end.unit untEmployee;interfaceuses
untPerson;type
TEmployee=class(TPerson)
private
FQuantity:Integer;
FWagePerItem:Real;
FSalary:Real;
public
constructor Create(NameValue:string;SalaryValue,WageperItemValue:Real;QuantityValue:Integer);
function Earnings:Real;override;
property WeeklySalary:Real read FSalary write FSalary;
property WagePerItem:Real read FWagePerItem write FWagePerItem;
property Quantity:Integer read FQuantity write FQuantity;
end;implementationconstructor Create(NameValue:string;SalaryValue,WageperItemValue:Real;QuantityValue:Integer);
begin
inherited Create(NameValue);
WeeklySalary:=SalaryValue;
WageperItem:=WageperItemValue;
Quantity:=QuantityValue;
end;function TEmployee.Earnings:Real;
begin
Result:=WeeklySalary+WagePerItem*Quantity;
end;
end.
unit untHourlyWorker;interfaceuses
untPerson;type
THourlyWorker=class(TPerson)
private
FHourWorked:Real;
FWage:Real;
public
constructor Create(NameValue:string;WageValue,HourWorkedValue:Real);
function Earnings:Real;override;
property Wage:Real read FWage write FWage;
property HourWorked:Real read FHourWorked write FHourWorked;
end;implementationconstructor Create(NameValue:string;WageValue,HourWorkedValue:Real);
begin
inherited Create(NameValue);
Wage:=WageValue;
HourWorked:=HourWorkedValue;
end;function THourlyWorker.Earnings:Real;
begin
if HoursWorked<=40 then
Result:=Wage*HoursWorked;
else
Result:=Wage*40+Wage*1.5*(HoursWorked-40);
end;
end.运行时错误提示如下:
[Error] untBoss.pas(22): Undeclared identifier: 'Create'
[Error] untBoss.pas(24): This form of method call only allowed in methods of derived types
[Error] untBoss.pas(24): Not enough actual parameters
[Error] untBoss.pas(25): Undeclared identifier: 'WeeklySalary'
[Error] untBoss.pas(13): Unsatisfied forward or external declaration: 'TBoss.Create'
[Fatal Error] Project1.dpr(9): Could not compile used unit 'untBoss.pas'
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure FormClick(Sender: TObject);
private
Persons:array[1..4] of TPerson;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
begin
Persons[1]:TBoss.Create('赵晓光',800.0);
Persons[2]:TEmployee.Create('钱明',400.0,3.0,150);
Persons[3]:TPieceWorker.Create('孙正',2.5,200);
Persons[4]:THourlyWorker.Create('李大',13.75,50.0);
end;procedure TForm1.FormDestory(Sender:TObject);
var
i:Integer;
begin
for i:=1 to 4 do begin
Persons[i].Free;
Persons[i]:=nil;
end;
end;procedure TForm1.FormClick(Sender: TObject);
var
i:Integer;
begin
for i:=1 to 4 do
ListBox1.Items.Add(Format('%8s %10.2f',[Person[i].Name,Person[i].Earnings]));
end;end.
unit untPerson;interfacetype
TPerson=class
private
FName:string;
public
constructor Create(NameValue:string);
function Earnings:Real;virtual;abstract;
property Name:string read FName write FName;
end;implementationconstructor TPerson.Create(NameValue:string);
begin
FName:=NameValue;
end;
end.type
TBoss=class(TPerson)
private
FSalary:Real;
public
constructor Create(NameValue:string;SalaryValue:Real);
function Earnings:Real;override;
property WeeklySalary:Real read FSalary write FSalary;
end;
implementationuses
SysUtils;constructor Create(NameValue:string;SalaryValue:Real);
begin
inherited Create(NameValue);
WeeklySalary:=SalaryValue;
end;function TBoss.Earnings:Real;
begin
Result:=WeeklySalary;
end;
end.
unit untPieceWork;interfaceuses
untPerson;type
TPieceWorker=class(TPerson)
private
FQuantity:Integer;
FWagePerPiece:Real;
public
constructor Create(NameValue:string;WagePerPieceValue:Real;QuantityValue:Integer);
function Earnings:Real;override;
property WagePerPiece:Real read FWagePerPiece write FWagePerPiece;
property Quantity:Real read FQuantity write FQuantity;
end;implementationconstructor Create(NameValue:string;WagePerPieceValue:Real;QuantityValue:Integer);
begin
inherited Create(NameValue);
WagePerPiece:=WagePerPieceValue;
Quantity:=QuantityValue;
end;function TPieceWorker.Earnings:Real;
begin
Result:=WagePerPiece*Quantity;
end;
end.unit untEmployee;interfaceuses
untPerson;type
TEmployee=class(TPerson)
private
FQuantity:Integer;
FWagePerItem:Real;
FSalary:Real;
public
constructor Create(NameValue:string;SalaryValue,WageperItemValue:Real;QuantityValue:Integer);
function Earnings:Real;override;
property WeeklySalary:Real read FSalary write FSalary;
property WagePerItem:Real read FWagePerItem write FWagePerItem;
property Quantity:Integer read FQuantity write FQuantity;
end;implementationconstructor Create(NameValue:string;SalaryValue,WageperItemValue:Real;QuantityValue:Integer);
begin
inherited Create(NameValue);
WeeklySalary:=SalaryValue;
WageperItem:=WageperItemValue;
Quantity:=QuantityValue;
end;function TEmployee.Earnings:Real;
begin
Result:=WeeklySalary+WagePerItem*Quantity;
end;
end.
unit untHourlyWorker;interfaceuses
untPerson;type
THourlyWorker=class(TPerson)
private
FHourWorked:Real;
FWage:Real;
public
constructor Create(NameValue:string;WageValue,HourWorkedValue:Real);
function Earnings:Real;override;
property Wage:Real read FWage write FWage;
property HourWorked:Real read FHourWorked write FHourWorked;
end;implementationconstructor Create(NameValue:string;WageValue,HourWorkedValue:Real);
begin
inherited Create(NameValue);
Wage:=WageValue;
HourWorked:=HourWorkedValue;
end;function THourlyWorker.Earnings:Real;
begin
if HoursWorked<=40 then
Result:=Wage*HoursWorked;
else
Result:=Wage*40+Wage*1.5*(HoursWorked-40);
end;
end.运行时错误提示如下:
[Error] untBoss.pas(22): Undeclared identifier: 'Create'
[Error] untBoss.pas(24): This form of method call only allowed in methods of derived types
[Error] untBoss.pas(24): Not enough actual parameters
[Error] untBoss.pas(25): Undeclared identifier: 'WeeklySalary'
[Error] untBoss.pas(13): Unsatisfied forward or external declaration: 'TBoss.Create'
[Fatal Error] Project1.dpr(9): Could not compile used unit 'untBoss.pas'
解决方案 »
- 开发人员用的电脑及笔记本显示器大小
- 两个id udpserver 一个收到信息做处理后如何返回给发送端?有代码
- 最近心情不好,大家说我该怎么才能留住她的心
- 大虾救命:XP下面的DELPHI7的LABLE的CAPTION汉字显示无法完整
- 我想新建一个满屏的Form,应该怎么办?
- Delphi如何做到监视一个WEB窗口的运行,并能截取WEB窗口发往网站的消息?在线等候...
- 一个小问题?
- 做过WebService/SOAP的兄弟请进。这里有一个头疼的问题。
- 菜鸟发问,Delphi中inherited是干嘛的?
- ?大峡们好.我想问一问.delphi里有没有keyboard这个单元.我安装一个控件说缺少,keyboard.dcu,怎么处理..?
- delphi判断点是否在多边形内
- 没学过delphi,刚下载了RAD Studio XE2,有没有教程啊?
constructor 类名.Create
比如constructor THourlyWorker.Create(NameValue:string;WageValue,HourWorkedValue:Real);
Forms,
untPerson in 'untPerson.pas' {Form1},
untBoss in 'untBoss.pas',
untEmployee in 'untEmployee.pas',
untPieceWork in 'untPieceWork.pas',
untHourlyWorker in 'untHourlyWorker.pas';{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
这种问题解决了,可是竟然出现了另外一个问题
[Error] Project1.dpr(15): Undeclared identifier: 'TForm1'
Forms,
untPerson in 'untPerson.pas' {Form1},
untBoss in 'untBoss.pas',
untEmployee in 'untEmployee.pas',
untPieceWork in 'untPieceWork.pas',
untHourlyWorker in 'untHourlyWorker.pas';{$R *.res}begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
那个问题解决了,但是出了新的问题:
[Error] Project1.dpr(15): Undeclared identifier: 'TForm1'
uses
Forms,
untPerson in 'untPerson.pas',
untBoss in 'untBoss.pas',
untEmployee in 'untEmployee.pas',
untPieceWork in 'untPieceWork.pas',
untHourlyWorker in 'untHourlyWorker.pas',
Unit1 in 'Unit1.pas' {Form1};
[Error] Project1.dpr(10): Declaration expected but identifier 'Unit1' found
[Error] Project1.dpr(15): Undeclared identifier: 'TForm1