Formatierungsfunktionen machen einen großen Teil von SysUtils aus. Einige von ihnen sind verschachtelt und bestehen aus ca. 1000 Zeilen Delphi Code. Dennoch funktioniert der nach C# übersetzte Code nahezu perfekt.
using System.Sysutils; using System; using static D7_formatting.D7_formattingImplementation; using static D7_formatting.D7_formattingInterface; using static System.SystemInterface; using static System.Sysutils.SysutilsInterface;
namespace D7_formatting
{
public class D7_formattingInterface
{
public static bool RunFormattingChecks()
{
bool result = false;
result = true;
if (!CheckBuildMessage())
result = false;
if (!CheckIdentifierLayout())
result = false;
if (!CheckFloatingPointText())
result = false;
return result;
}
} // class D7_formattingInterface
file class D7_formattingImplementation
{
public static bool CheckBuildMessage()
{
bool result = false;
string MessageText = string.Empty;
MessageText = Format("Build %s produced %d artifacts", new TVarRec[] { "linux-x64", 18 });
result = MessageText == "Build linux-x64 produced 18 artifacts";
return result;
}
public static bool CheckIdentifierLayout()
{
bool result = false;
result = true;
if (Format("ID-%6.4d", new TVarRec[] { 73 }) != "ID- 0073")
result = false;
if (Format("HEX-%4.4x", new TVarRec[] { 0x2A }) != "HEX-002A")
result = false;
if (Format("%1:s/%0:s/%1:s", new TVarRec[] { "source", "target" }) != "target/source/target")
result = false;
return result;
}
public static bool CheckFloatingPointText()
{
bool result = false;
TFormatSettings SavedSettings = TFormatSettings.CreateRecord();
double Measurement = 0.0D;
SavedSettings = FormatSettings;
try
{
FormatSettings.DecimalSeparator = ',';
FormatSettings.ThousandSeparator = '.';
Measurement = 4312.24D;
result = true;
if (FloatToStr(12.5D) != "12,5")
result = false;
if (FloatToStr(1E40D) != "1E40")
result = false;
if (FormatFloat("#,##0.00", Measurement) != "4.312,24")
result = false;
if (FormatFloat("000000", Measurement) != "004312")
result = false;
if (FormatFloat("0.000", Measurement) != "4312,240")
result = false;
if (FormatFloat("0.000E+00", Measurement) != "4,312E+03")
result = false;
if (FormatFloat("0.0 \"up\";0.0 \"down\"", -Measurement) != "4312,2 down")
result = false;
if (FormatFloat("0.0;-0.0;\"idle\"", 0.0F) != "idle")
result = false;
}
finally
{
FormatSettings = SavedSettings;
}
return result;
}
} // class D7_formattingImplementation
} // namespace D7_formatting
Der Code wurde generiert aus:
unit d7_formatting;
interface
function RunFormattingChecks: Boolean;
implementation
uses System.SysUtils;
function CheckBuildMessage: Boolean;
var
MessageText: string;
begin
MessageText := Format('Build %s produced %d artifacts',
['linux-x64', 18]);
Result := MessageText =
'Build linux-x64 produced 18 artifacts';
end;
function CheckIdentifierLayout: Boolean; begin Result := True;
if Format('ID-%6.4d', [73]) <> 'ID- 0073' then
Result := False;
if Format('HEX-%4.4x', [$2A]) <> 'HEX-002A' then
Result := False;
if Format('%1:s/%0:s/%1:s', ['source', 'target']) <>
'target/source/target' then
Result := False;
end;
function CheckFloatingPointText: Boolean;
var
SavedSettings: TFormatSettings;
Measurement: Double;
begin
SavedSettings := FormatSettings;
try
FormatSettings.DecimalSeparator := ',';
FormatSettings.ThousandSeparator := '.';
Measurement := 4312.24;
Result := True;
if FloatToStr(12.5) <> '12,5' then
Result := False;
if FloatToStr(1E40) <> '1E40' then
Result := False;
if FormatFloat('#,##0.00', Measurement) <> '4.312,24' then
Result := False;
if FormatFloat('000000', Measurement) <> '004312' then
Result := False;
if FormatFloat('0.000', Measurement) <> '4312,240' then
Result := False;
if FormatFloat('0.000E+00', Measurement) <> '4,312E+03' then
Result := False;
if FormatFloat('0.0 "up";0.0 "down"', -Measurement) <>
'4312,2 down' then
Result := False;
if FormatFloat('0.0;-0.0;"idle"', 0) <> 'idle' then
Result := False;
finally
FormatSettings := SavedSettings;
end;
end;
function RunFormattingChecks: Boolean; begin Result := True;
if not CheckBuildMessage then
Result := False;
if not CheckIdentifierLayout then
Result := False;
if not CheckFloatingPointText then
Result := False;
end;
end.
English
| Letzte Neuigkeiten |
|
01.09.26
Delphi2C# 2.8.0: Grundlegend überarbeitete Zeigersimulation [mehr...] |
|
18.05.26
Delphi2C# 2.7.0: Übersetzungsheuristiken [mehr...] |
|
Diese Homepage ist aus einfachen Texten mit
[Minimal Website]
generiert.
|
Minimal Website ist mit Hilfe des TextTransformers hergestellt.
|
Der TextTransformer ist gemacht mit dem Borland
C++Builder
|