Mega Code Archive

 
Categories / Delphi / Examples
 

Using format[] to format your code

When you have to construct long strings combining different types of data using many functions in between, it maybe better and easier to use the "Format()" functions instead of using "+" signs. For example, consider the following simple string (assuming that "sName" is a string variable containing a name): 'My name is ' + sName + ' and I am ' + IntToStr( 16 ) + ' years old' It's better to use "Format()" to achieve the same result, because it makes it easier to read and format your source code: Format( 'My name is %s and I am %d years old', [ sName, 16 ] ) Of course, "Format()" can handle many other types of data and format them in many ways, so be sure to lookup help for it.