chami.com/tips/
Last  Home  Next
 Internet
 Programming
 Windows


Click for details
Keywords
Delphi 2.x
Delphi 3.x
Delphi
Functions

Downloads
strcc.pas
strcc2.pas

Using Format() to format your code

    See Also
  How to create functions that can accept variable number of parameters such as Format()

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'
'
Listing #1 : Delphi code. Right click strcc.pas to download.

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 ] )
Listing #2 : Delphi code. Right click strcc2.pas to download.

Of course, "Format()" can handle many other types of data and format them in many ways, so be sure to lookup help for it.

 
Related Links Email Print 
Created on 21-Jan-1997. Source code colorized using CodeColorizer.
Copyright (C) 1996-99 Chami.com All Rights Reserved. Reproduction in whole or in part
or in any form or medium without express written permission of Chami.com is prohibited.
Information on this page is provided as-is without warranty of any kind. Use at your own risk.
Free Downloads | Products & Services | Privacy Statement | Terms & Conditions | Advertising Info