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
Delphi Basics 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.)
using System.Classes; using static System.Classes.ClassesInterface; using static dbsc_tstringlist.dbsc_tstringlistInterface; using static dbsc_tstringlist.dbsc_tstringlistImplementation; using System; using static System.SystemInterface;
namespace dbsc_tstringlist {
public class dbsc_tstringlistInterface {
//http://www.delphibasics.co.uk/RTL.asp?Name=TStringList public static bool TStringListTest() { bool result = false; result = true; result = result && TStringListTest1(); result = result && TStringListTest2(); result = result && TStringListTest3(); return result; }
} // class dbsc_tstringlistInterface
public class dbsc_tstringlistImplementation {
public static bool TStringListTest1() { bool result = false; TStringList animals = null; // 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("Cat"); animals.Add("Mouse"); animals.Add("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[0] == "Cat"); result = result && (animals[1] == "Mouse"); result = result && (animals[2] == "Giraffe");
// Free up the list object animals = null; return result; }
public static bool TStringListTest2() { bool result = false; TStringList Names = null; // Define our string list variable string ageStr = string.Empty; int i = 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.CommaText = "Neil=45, Brian=63, Jim=22";
// And now find Brian's age ageStr = Names.ReadPropertyValues("Brian");
// Display this value // ShowMessage('Brians age = '+ageStr); result = result && (ageStr == "63");
// Now display all name and age pair values for(i = 0; i <= Names.Count - 1; i++) { //ShowMessage(names.Names[i]+' is '+names.ValueFromIndex[i]); if(i == 0) result = result && (new PChar(Names.ReadPropertyNames(i)).ToString() == "Neil") && (new PChar(Names.ReadPropertyValueFromIndex(i)).ToString() == "45"); if(i == 1) result = result && (new PChar(Names.ReadPropertyNames(i)).ToString() == "Brian") && (new PChar(Names.ReadPropertyValueFromIndex(i)).ToString() == "63"); if(i == 2) result = result && (new PChar(Names.ReadPropertyNames(i)).ToString() == "Jim") && (new PChar(Names.ReadPropertyValueFromIndex(i)).ToString() == "22"); }
// Free up the list object Names = null; return result; }
public static bool TStringListTest3() { bool result = false; TStringList cars = null; // 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.Delimiter = ' '; // Each list item will be blank separated cars.QuoteChar = '|'; // And each item will be quoted with |'s cars.DelimitedText = "|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[0] == "Honda Jazz"); result = result && (cars[1] == "Ford Mondeo"); result = result && (cars[2] == "Jaguar \"E-type\"");
// Free up the list object cars = null; return result; }
} // class dbsc_tstringlistImplementation
} // namespace dbsc_tstringlist
english
Letzte Neuigkeiten |
28.10.24
Delphi2C# 2.5: in Groß- und Kleinschreibung mit Deklarationen übereinstimmende Symbolnamen [more...] |
29.01.24
Aurora2Cpp: Delphi 7 Konverter [more...] |
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
CBuilder
|