texttransformer.jpg

Eine häufig verwendete Delphi Klasse ist TStringList. Die Übersetzung des Codes aus System.Classes nach C++ benötigt nur wenig manuelle Nachbearbeitung. Die Beispiele aus

dbsc_TStringList

kompilieren und funktionieren einwandfrei, ohne dass der Code manuell nachbearbeitet werden müsste. (Wie bei den anderen Beispielen hier, ist der Originalcode wiedr leicht modifiziert worden, um ihe für Testzwecke verwendbar zu nachen.)



#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


   english english

 

 
Letzte Neuigkeiten
29.01.24
Aurora2Cpp: Delphi 7 Konverter [more...]

19.10.23
Delphi2Cpp 2.3: Konvertierung von DFM-Dateien [more...]



[aus Fallstudie...]

"Eine Meisterleistung -- Delphi2Cpp hat alle meine Erwartungen weit übertroffen."


Tony Hürlimann
virtual-optima 29.08.2011



"Ich muss mich nochmal für deinen Einsatz und die Qualität deiner Arbeit bedanken, das ist absolut überdurchschnittlich ..."


Gerald Ebner


 
Diese Homepage ist aus einfachen Texten mit [Minimal Website ]generiert.

Minimal Website
Minimal Website ist mit Hilfe des TextTransformers hergestellt.

TextTransformer
Der TextTransformer ist gemacht mit dem Borland CBuilder

  borland