Format is a very common method, but it seems that I have tried some translators to help this method, let it have a complete profile for everyone to use: First look at its statement: function format (const) Format: string; constrays: string; overload; in fact the Format method has two forms, the other is three parameters, the main difference is that it is thread safe, but not much, so Here is only the first introduction: Function Format (const format: string; const args: array f const): string; overload; format parameter is a format string for formatting the value in Args. What is args, it is a variant array, that is, there can be multiple parameters in it, and each parameter can be different. As: format ('wind'], ['wind']); return is my name is Wind now to see the format parameter for details: Format can write ordinary strings, such as' my name IS ', but some format instruction characters have special meaning, such as "% 6s" format instructions have the following form: "%" [index ":"] ["-" [width] ["." prec] type it is "%" Begins, but the end of TYPE, Type represents a specific type. The intermediate is used to format the Type type instruction character, is optional. Let's see Type, Type can be the following characters: D 10, indicating that a integer value U and D are integer, but it is no symbol, and if it corresponds to the value, return At a time of 2, a number of absolute values, such as: format ('this is% u', [- 2]); returning: THIS IS 4294967294F corresponds to floating point number E Science representation, corresponding integer Number and floating point, such as Format ('this is% e', [- 2.22]); return: this is -2.2200000000000000e 000, etc. And it will remove the amounts of the value in the value such as Format ('this IS% G', [02.200]); returned: this is 2.2n can only correspond to the floating point, and the value is converted to the number.
Looking at an example, I understand Format ('this is% n', [4552.2176]); returning to this is 4,552.22 Note There are two points, one is only two digits after the decimal, wait for this to eliminate this Yes, even if the decimal is not truncated, it will not also be separated by the M coin type as an integer part, but about the currency type has a better format method, here is just simple formatting, it is only a floating Point value format ('this is% m', [9552.21]); Return: This is ¥ 9,552.21p corresponds to the pointer type, the returned value is the address of the pointer, indicating, for example, VAR X: Integer; p: ^ integer; begin x: = 99; p: = @ x; edit1.text: = format ('this is% p', [p]); END; edit1 content is: this is 0012f548s corresponding characters String type, don't say more, x must be a intepier value, return Edit1.Text: = Format ('this is% x', [15]) in hexadecimal form; return is: this isf type After completion, the following is introduced to format Type's instructions: [INDEX ":"] How to express it, see an example format ('this is% D% d', [12, 13]); one of the first% D Index is 0, the second% D is 1, so the character display is like this is this is 12 13 and if you define: format ('this is% 1: D% 0: D', [12, 13]) Then, the returned string turns this is IS 13 12 now understands, [Index ":"] Index indicates that there is a situation in the order in Args, if so Format ('% D% D% D% 0: D% d ', [1, 2, 3, 4]) will return 1 2 3 1 2. If you want to return 1 2 3 1 4, you must do this: Format ('% D% D% D% 0: D% 3: D', [1, 2, 3, 4]), when used Note that the index cannot exceed the number in Args, otherwise it will cause an exception such as Format ('this is% 2: D% 0: D', [12, 13]); because only 12 13 in the ARGS, INDEX Can only be 0 or 1, here is 2 or wrong [width] Specifies the width of the value that will be formatted, seeing an example, understand Format ('this is% 4d', [12]); output is: This is 12 is relatively easy, but if the value of width is less than the length of the parameter, there is no effect.
Such as: format ('this is% 1D', [12]); output is: this is 12 ["-"] This specified parameter is left to Zuo Qi, and [width] is best to see the effect: Format (' This is% -4d, yes ', [12]); output is: this is 12, yes ["." prec] Specify precision, best for floating point: Format (' this is% .2f ', [' 1.1234]); Output this is 1.12 Format ('1.1234]); lost this IS 1.1234000 and for integer, if PREC is small, there is no effect, The number of intersive values is large, and the front of the integer value is 0 to Format ('this is% .7d', [1234]); the output is: this is 0001234] For characters, just, and integer values Conversely, if PREC is not effective if PREC is large, it is not a result than the length of the character string type, the character format of the tail will be cut off the tail, and ['THIS% .2S', ['1234']); output is this IS 12 and this example: Format ('this is% e', [- 2.22]); return: this is -2.2200000000000000e 000 how to get extra 0, this is OK Format ('this is % .2e ', [- 2.22]); Ok, the first time is finished, it should be familiar with him. /// BII FORMATDATETIME Usage His Declaration is: function formattime (const format: string; DateTime: tdatetime): String; OVERLOAD; of course, there is one as Format, but here only introduces the first one The Format parameter is a formatted string. DateTime is a time type. The return value is a formatted string key to see the command character c in the Format parameter display time in a short time format, that is, all the numbers represent formetime ('c', now); output is: 2004-8- 7 9:55:40d Corresponds to the date, the date is a bit shows one bit, two bits display two formatDatetime ('d', now); output may be the same as 1 ~ 31DD and D, but It is always the formtdatetime ('DD', NOW) that is displayed in two; output may be 01 ~ 31DDD display is the day of the week formatDateTime ('DDD', NOW); the output is the same as the Saturday DDDD and DDD . But the above two may not be the same in other countries.
DDDDD Displays the Year Month Day Formator ('DDDD', NOW) in a short-time format; output is: 2004-8-7ddddddd Demonstrate FormatDateTime ('DDDDD', NOW) in long-term format; output is: August 2004 7-day E / EE / EEE / EEEE displays the year formtdatetime ('EE', NOW); output is: 04 (representative 04) m / mm / mmm / mmmm represents Month FormatorTime ('M', NOW ); 8 formatdatetime ('mm', now); output is 08 Formator ('mmm', now); output is August Formator ('mmmm', now); output is the same as DDD / DDDD, In other countries, different YY / YYYY indicate that year formatdatetime ('yy', now); output is 04 Formator ('YYY', NOW); output is 2004H / hh, n / nn, s / s, z / zzz respectively Hours, minute, second, milliseconds Time formatDatetime ('t', now) is displayed in a short time format; output is 10: 17tt display time formatdatetime ('TT', NOW) in long-term format; output is 10:18:46 AMPM Show the morning in the morning or the afternoon, formatdatetime ('ttampm', now); output is: 10: 22: 57 Amon, if you want to add a normal string in Format, you can use double quotes to separate those specificizable Character, such a normal string if special characters will not be displayed as time format: formatdatetime ('"Today IS" c', now); output is: Today is 2004-8-7 10:26:58 The time can also be added "-" or "/" to separate the date: formatdatetime ('"Today IS" YY-MM-DD', NOW); FormatorTDime ('"Today IS" YY / mm / DD', NOW); Output is: Today IS 04-0 8-07 can also use ":" to separate time formtime ('"Today IS" HH: NN: SS', NOW); output is: Today is 10:32:23 / Three.Matfloat Usage Common Declaration: Function Formatfloat (const format: string; string; overload; same format parameter is the formatting instruction character, why is the extended type why is this type because it is the largest in all floating point values, if Parameters that are incompatient, such as Double or others, can be saved. The key is to see the usage of the Format parameter 0 This specified directive of the corresponding number of bits.