Reputation:
I am new on Delphi, i have some code writed with Java. It has an inner class structure. But i dont know how to convert to 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.
I declared TResolutionLevel for inner class, but how can i implement this class' s method in where?
Upvotes: 3
Views: 366
Reputation: 28516
If you press Shift+Ctrl+C while you are inside your class interface declarations Delphi will automatically generate missing methods. In your case those are:
{ 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;
As you can see, you implement the inner class's methods the same way as you implement any other class's methods, by giving the fully qualified name of each method. In the case of a nested class, that means including the name of the outer class(es).
Upvotes: 3