FormatString is not a regular Pascal function. It's a compiler built-in that's expanded to a sequence of "magic" RTS calls, one of the last of them being InternalFormatString. At this point, the variable arguments have already been pre-converted to strings and put in an array (`Strings^'), so the function only needs to deal with an array of variable size. (Admittedly, it currently doesn't use one of the standard ways (conformant array or schema) or BP open arrays but a formally-unbounded array, but we may change this, and it's unrelated to the "varargs" question.)
I would be interested to modify InternalFormatString to handle padding.
I propose to replace the unused character after the '%' by the character used to pad the corresponding field (if it is not alphabetic). This way, existing code with %d, %s, ... will continue to work as before.
Doing this s := FormatString('Display 00042: %0', 42:5); would produce 'Display 00042: 00042'. s := FormatString('Display ***Hello: %*', 'Hello':8); would produce 'Display ***Hello: ***Hello'.
Please give me your advice. I won't do anything with approval.
Other related question: Is there a way I can test the modification to InternalFormatString without installing the runtime library system-wide? (just in case it does not work ;-)
Kind regards
Pascal