Description |
Converts the current salient Object contents into a formatted string.
This is a very important method - allowing all classes to show themselves as it were.
For the base Object type, there are no real contents, so the class name itself is used as the string. For your classes, you should define a meaningful ToString implementation. For example, the Exception class displays the trace of exceptions it contains.
|
|
Microsoft MSDN Links |
System
System.Object
|
|
|
A simple example |
program Project1;
{$APPTYPE CONSOLE}
var
MyObj : System.Object;
MyStr : String;
begin
// Instantiate the object
MyObj := System.Object.Create;
Console.WriteLine('MyObj.ToString = ' + MyObj.ToString);
// Define the string contents (strings aer automatically created)
MyStr := 'Hello World';
Console.WriteLine('MyStr.ToString = ' + MyStr.ToString);
Console.ReadLine;
end.
| Show full unit code | MyObj.ToString = System.Object
MyStr.ToString = Hello World
|
|
|
|