t2t-soft

A frequently used Delphi class is TStringList. The translation of the defining code in System.Classes needs little manual post-processing. The example from

dbsc_TStringList

compiles and works without manual post-processing. (Again, the original code has been slightly modified for the testing purpose.)




#include "dbsc_tstringlist.h"
#include "d2c_convert.h"

using namespace std;
using namespace System;
using namespace System::Classes;

namespace dbsc_tstringlist
{
bool TStringListTest1()
{
  bool result = false;
  TStringList* animals = nullptr;            // Define our string list variable
  int i = 0;
  result = true;
  // Define a string list object, and point our variable at it
  animals = new TStringList();

  // Now add some names to our list
  animals->Add(L"Cat");
  animals->Add(L"Mouse");
  animals->Add(L"Giraffe");

  // Now display these animals
  // for i := 0 to animals.Count-1 do
  //  ShowMessage(animals[i]);  // animals[i] equates to animals.Strings[i]
  result = result && (animals->ReadPropertyStrings(0) == L"Cat");
  result = result && (animals->ReadPropertyStrings(1) == L"Mouse");
  result = result && (animals->ReadPropertyStrings(2) == L"Giraffe");

  // Free up the list object
  delete animals;
  return result;
}

bool TStringListTest2()
{
  bool result = false;
  TStringList* Names = nullptr;            // Define our string list variable
  String ageStr;
  int i = 0;
  int stop = 0;
  result = true;
  // Define a string list object, and point our variable at it
  Names = new TStringList();

  // Now add some names to our list
  Names->WritePropertyCommaText(L"Neil=45, Brian=63, Jim=22");

  // And now find Brian's age
  ageStr = Names->ReadPropertyValues(L"Brian");

  // Display this value
  // ShowMessage('Brians age = '+ageStr);
  result = result && (ageStr == L"63");

  // Now display all name and age pair values
  for(stop = Names->ReadPropertyCount() - 1, i = 0; i <= stop; i++)
  {
     //ShowMessage(names.Names[i]+' is '+names.ValueFromIndex[i]);
    if(i == 0)
      result = result && (String(ustr2pwchar(Names->ReadPropertyNames(i))) == L"Neil") && (String(ustr2pwchar(Names->ReadPropertyValueFromIndex(i))) == L"45");
    if(i == 1)
      result = result && (String(ustr2pwchar(Names->ReadPropertyNames(i))) == L"Brian") && (String(ustr2pwchar(Names->ReadPropertyValueFromIndex(i))) == L"63");
    if(i == 2)
      result = result && (String(ustr2pwchar(Names->ReadPropertyNames(i))) == L"Jim") && (String(ustr2pwchar(Names->ReadPropertyValueFromIndex(i))) == L"22");
  }

  // Free up the list object
  delete Names;
  return result;
}

bool TStringListTest3()
{
  bool result = false;
  TStringList* cars = nullptr;            // Define our string list variable
  int i = 0;
  result = true;
  // Define a string list object, and point our variable at it
  cars = new TStringList();

  // Now add some cars to our list - using the DelimitedText property
  // with overriden control variables
  cars->WritePropertyDelimiter(L' ');        // Each list item will be blank separated
  cars->WritePropertyQuoteChar(L'|');        // And each item will be quoted with |'s
  cars->WritePropertyDelimitedText(L"|Honda Jazz| |Ford Mondeo| |Jaguar \"E-type\"|");

  // Now display these cars
//  for i := 0 to cars.Count-1 do
//    ShowMessage(cars[i]);       // cars[i] equates to cars.Strings[i]
  result = result && (cars->ReadPropertyStrings(0) == L"Honda Jazz");
  result = result && (cars->ReadPropertyStrings(1) == L"Ford Mondeo");
  result = result && (cars->ReadPropertyStrings(2) == L"Jaguar \"E-type\"");

  // Free up the list object
  delete cars;
  return result;
}

bool TStringListTest()
{
  bool result = false;
  result = true;
  result = result && TStringListTest1();
  result = result && TStringListTest2();
  result = result && TStringListTest3();
  return result;
}
}  // namespace dbsc_tstringlist


   deutsch Deutsch


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

11/18/25
Delphi2Cpp 2.6: Delphi Interfaces [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