Java Delphi 中的 Class 内部
Java Inner Class in Delphi
我是 Delphi 的新手,我有一些代码是用 Java 编写的。它有一个内部 class 结构。但我不知道如何转换为 Delphi.
unit resolutionSet;
interface
uses
Winapi.Windows, System.Math;
type
TResolutionSet = class
type
TResolutionLevel = class
private
{ private declarations }
discardLayers : Integer;
dims : TRect;
function getZoomLevel : Integer;
function getZoomPercent : Double;
function getResolutionBounds : TRect;
constructor Create(_discardLayers : Integer; _dims : TRect) overload;
protected
{ protected declarations }
public
{ public declarations }
published
{ published declarations }
end;
private
{ private declarations }
resolutions : array of TResolutionLevel;
protected
{ protected declarations }
public
{ public declarations }
function getResolutionLevel(_currRes : TResolutionLevel; _delta : Integer) : TResolutionLevel overload;
function getResolutionLevel(_index : Integer) : TResolutionLevel overload;
function getClosestResolutionLevel(_source : Double; _target : Double) : TResolutionLevel;
procedure addResolutionLevel(_discardLayer : Integer; _dims : TRect);
constructor Create(_numResolutions : Integer) overload;
published
{ published declarations }
end;
implementation
constructor TResolutionSet.Create(_numResolutions : Integer) overload;
begin
SetLength(resolutions, _numResolutions);
end;
procedure TResolutionSet.addResolutionLevel(_discardLayer : Integer; _dims : TRect);
begin
resolutions[_discardLayer]:= TResolutionLevel.Create(_discardLayer, _dims);
end;
function TResolutionSet.getResolutionLevel(_currRes : TResolutionLevel; _delta : Integer) : TResolutionLevel overload;
begin
//Result:= resolutions
end;
function TResolutionSet.getResolutionLevel(_index : Integer) : TResolutionLevel overload;
begin
Result:= resolutions[_index];
end;
function TResolutionSet.getClosestResolutionLevel(_source : Double; _target : Double) : TResolutionLevel;
var
idx : Integer = 0;
i : Integer;
begin
for i := Length(resolutions)-1 downto 0 do
begin
idx:= i;
if (_source * Power(2, resolutions[i].getZoomLevel())) <= _target then
break;
end;
Result:= resolutions[idx];
end;
end.
我为内部 class 声明了 TResolutionLevel,但我如何在何处实现此 class 的方法?
如果您在 class 接口声明 Delphi 将自动生成缺少的方法。在您的情况下,它们是:
{ TResolutionSet.TResolutionLevel }
constructor TResolutionSet.TResolutionLevel.Create(_discardLayers: Integer; _dims: TRect);
begin
end;
function TResolutionSet.TResolutionLevel.getResolutionBounds: TRect;
begin
end;
function TResolutionSet.TResolutionLevel.getZoomLevel: Integer;
begin
end;
function TResolutionSet.TResolutionLevel.getZoomPercent: Double;
begin
end;
如您所见,实现内部 class 方法的方式与实现任何其他 class 方法的方式相同,方法是给出每个方法的完全限定名称。在嵌套 class 的情况下,这意味着包括外部 class(es).
的名称
我是 Delphi 的新手,我有一些代码是用 Java 编写的。它有一个内部 class 结构。但我不知道如何转换为 Delphi.
unit resolutionSet;
interface
uses
Winapi.Windows, System.Math;
type
TResolutionSet = class
type
TResolutionLevel = class
private
{ private declarations }
discardLayers : Integer;
dims : TRect;
function getZoomLevel : Integer;
function getZoomPercent : Double;
function getResolutionBounds : TRect;
constructor Create(_discardLayers : Integer; _dims : TRect) overload;
protected
{ protected declarations }
public
{ public declarations }
published
{ published declarations }
end;
private
{ private declarations }
resolutions : array of TResolutionLevel;
protected
{ protected declarations }
public
{ public declarations }
function getResolutionLevel(_currRes : TResolutionLevel; _delta : Integer) : TResolutionLevel overload;
function getResolutionLevel(_index : Integer) : TResolutionLevel overload;
function getClosestResolutionLevel(_source : Double; _target : Double) : TResolutionLevel;
procedure addResolutionLevel(_discardLayer : Integer; _dims : TRect);
constructor Create(_numResolutions : Integer) overload;
published
{ published declarations }
end;
implementation
constructor TResolutionSet.Create(_numResolutions : Integer) overload;
begin
SetLength(resolutions, _numResolutions);
end;
procedure TResolutionSet.addResolutionLevel(_discardLayer : Integer; _dims : TRect);
begin
resolutions[_discardLayer]:= TResolutionLevel.Create(_discardLayer, _dims);
end;
function TResolutionSet.getResolutionLevel(_currRes : TResolutionLevel; _delta : Integer) : TResolutionLevel overload;
begin
//Result:= resolutions
end;
function TResolutionSet.getResolutionLevel(_index : Integer) : TResolutionLevel overload;
begin
Result:= resolutions[_index];
end;
function TResolutionSet.getClosestResolutionLevel(_source : Double; _target : Double) : TResolutionLevel;
var
idx : Integer = 0;
i : Integer;
begin
for i := Length(resolutions)-1 downto 0 do
begin
idx:= i;
if (_source * Power(2, resolutions[i].getZoomLevel())) <= _target then
break;
end;
Result:= resolutions[idx];
end;
end.
我为内部 class 声明了 TResolutionLevel,但我如何在何处实现此 class 的方法?
如果您在 class 接口声明 Delphi 将自动生成缺少的方法。在您的情况下,它们是:
{ TResolutionSet.TResolutionLevel }
constructor TResolutionSet.TResolutionLevel.Create(_discardLayers: Integer; _dims: TRect);
begin
end;
function TResolutionSet.TResolutionLevel.getResolutionBounds: TRect;
begin
end;
function TResolutionSet.TResolutionLevel.getZoomLevel: Integer;
begin
end;
function TResolutionSet.TResolutionLevel.getZoomPercent: Double;
begin
end;
如您所见,实现内部 class 方法的方式与实现任何其他 class 方法的方式相同,方法是给出每个方法的完全限定名称。在嵌套 class 的情况下,这意味着包括外部 class(es).
的名称