t2t-soft

The formatting routines account for a considerable part of the SysUtils unit. Some of them are nested and consist in about 1000 lines of code. Nevertheless the translated code works nearly perfect.


#include "pch.h"

#include "d7_formatting.h"
#include "System.SysUtils.h"
#include "d2c_sysvariant.h"
#include "d2c_openarray.h"
#include "OnLeavingScope.h"

using namespace std;
using namespace d2c_system;
using namespace System;
using namespace System::Sysutils;

namespace D7_formatting
{

bool CheckBuildMessage()
{
  bool result = false;
  String MessageText;
  MessageText = Format(L"Build %s produced %d artifacts", ArrayOfConst(String(L"linux-x64"), 18));
  result = MessageText == L"Build linux-x64 produced 18 artifacts";
  return result;
}

bool CheckIdentifierLayout()
{
  bool result = false;
  result = true;
  if(Format(L"ID-%6.4d", ArrayOfConst(73)) != L"ID-  0073")
    result = false;
  if(Format(L"HEX-%4.4x", ArrayOfConst(0x2A)) != L"HEX-002A")
    result = false;
  if(Format(L"%1:s/%0:s/%1:s", ArrayOfConst(String(L"source"), String(L"target"))) != L"target/source/target")
    result = false;
  return result;
}

bool CheckFloatingPointText()
{
  bool result = false;
  TFormatSettings SavedSettings = {};
  double Measurement = 0.0;
  SavedSettings = FormatSettings;
  {
    auto olsLambda = onLeavingScope([&] 
    {
      FormatSettings = SavedSettings;
    });
    FormatSettings.DecimalSeparator = L',';
    FormatSettings.ThousandSeparator = L'.';
    Measurement = 4312.24;
    result = true;
    if(FloatToStr(12.5L) != L"12,5")
      result = false;
    if(FloatToStr(1E40L) != L"1E40")
      result = false;
    if(FormatFloat(L"#,##0.00", Measurement) != L"4.312,24")
      result = false;
    if(FormatFloat(L"000000", Measurement) != L"004312")
      result = false;
    if(FormatFloat(L"0.000", Measurement) != L"4312,240")
      result = false;
    if(FormatFloat(L"0.000E+00", Measurement) != L"4,312E+03")
      result = false;
    if(FormatFloat(L"0.0 \"up\";0.0 \"down\"", -Measurement) != L"4312,2 down")
      result = false;
    if(FormatFloat(L"0.0;-0.0;\"idle\"", 0.0L) != L"idle")
      result = false;
  }
  return result;
}

bool RunFormattingChecks()
{
  bool result = false;
  result = true;
  if(!CheckBuildMessage())
    result = false;
  if(!CheckIdentifierLayout())
    result = false;
  if(!CheckFloatingPointText())
    result = false;
  return result;
}

}  // namespace D7_formatting

The code was generated from:


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.



   deutsch Deutsch


 
Latest News
09/01/26
Delphi2Cpp 2.8.0: Maintenance Update with Bug Fixes and Improvements [more...]

05/18/26
Delphi2Cpp 2.7: Translation heuristics [more...]



"We have successfully completed the projects, and the applications are (for the most part) already running at our customers' sites."





"Thanks for your great work, really appreciate the work you have done on zlib and compiling ... test case."


Mattewada, Udayabhaskar
Nokia India 02/01/2021




[from case study...]

"A masterpiece -- Delphi2Cpp has exceeded all my expectations by far."


Tony Hürlimann
virtual-optima 08/20/2011



"First off, I have to say WOW! Delphi2Cpp is doing a *fantastic* job!"


Daniel Flower
linkrealms 01/15/2011



"Though we have not finished the conversion yet, I'm glad that we've found you and could transform Eurocap to C++ with the help of Delphi2CB and you. (And I'm also glad that we could help you to make Delphi2CB better😉)"


Gáspár Huba


 
This website is generated from plain text with [Minimal Website]

Minimal Website
 
Minimal Website is made with TextTransformer

TextTransformer
 
TextTransformer is made with Borland C++Builder

  Borland