J
javesun
Unregistered / Unconfirmed
GUEST, unregistred user!
type
ICompare = interface
['{DDFE0840-E8FB-11D2-9085-0040F6741DE2}']
function CompareWith(ACompare: ICompare
ASortBy: Integer): Integer;
end;
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
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;
以上有省略。。。。。
Emp := ACompare as IEmployee...
1、两个接口没有任何关系,这个地方用as作什么?
2、哪位高人能详细解释一下as的用法。。。
ICompare = interface
['{DDFE0840-E8FB-11D2-9085-0040F6741DE2}']
function CompareWith(ACompare: ICompare
ASortBy: Integer): Integer;
end;
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
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;
以上有省略。。。。。
Emp := ACompare as IEmployee...
1、两个接口没有任何关系,这个地方用as作什么?
2、哪位高人能详细解释一下as的用法。。。