我是Delphi的新手,我有一些用Java编写的代码。它具有内部类结构。但是我不知道如何转换为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.
我为内部类声明了TResolutionLevel,但是如何在哪里实现此类的方法呢?
如果您在类接口声明中时按Shift+ Ctrl+ C,则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;
如您所见,通过提供每个方法的完全限定名称,您可以像实现任何其他类的方法一样实现内部类的方法。对于嵌套类,这意味着包括外部类的名称。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句