📄 empunit.pas
字号:
unit EmpUnit;
interface
uses
SysUtils, IntfUnit;
type
TEmployeeOrder = (eoName, eoSalary);
IEmployee = interface
['{FFCD24F0-4FE8-11D3-B84D-0040F67455FE}']
function GetName: string;
function GetSalary: Double;
end;
TEmployee = class(TInterfacedObject, IEmployee, ICompare)
private
FName: string;
FSalary: double;
public
constructor Create(AName: string; ASalary: Double);
function CompareWith(ACompare: ICompare;
ASortBy: Integer): Integer;
function GetName: string;
function GetSalary: Double;
end;
implementation
{ TEmployee }
function TEmployee.CompareWith(ACompare: ICompare;
ASortBy: Integer): Integer;
var
Emp: IEmployee;
begin
Result := 0;
Emp := ACompare as IEmployee;
case ASortBy of
Ord(eoName):
Result := CompareStr(FName, Emp.GetName);
Ord(eoSalary):
if FSalary < Emp.GetSalary then
Result := -1
else if FSalary > Emp.GetSalary then
Result := 1
else
Result := 0;
end;
end;
constructor TEmployee.Create(AName: string; ASalary: Double);
begin
inherited Create;
FName := AName;
FSalary := ASalary;
end;
function TEmployee.GetName: string;
begin
Result := FName;
end;
function TEmployee.GetSalary: Double;
begin
Result := FSalary;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -