Array of Variant as Parameter List
Array of Variant as Parameter List
I was recently coding a Pascal-standard format() function for my Nice EWB library because EWB does not include that function.
So you could write
format( formatstring : string ; args : array of variant );
format("hex numbers %8x, %4x", [123, 2345] );
A benefit of format() is that you can create readable content without constantly unquoting, adding IntToStr(), FloatToStr(), etc.
Also, format() handles hexadecimal output better than EWB’s internal routine, supports thousands separators if desired, money, and avoids the demical floating point errors because when you specify a precicsion (number of demical places), the value is correclty observed.
Due to math, Binary numbers cannot correctly represent fractions very accurately. This commonly causes problems when you wish to display dollars.cents like $10.01 and the computer spits out $10.01000001 or something similar. Format edits the string output of FloatToStr() to limit to precisely the numbe of digits intended.
So the problem one might think of is how to handle an unknown number of variables of non-predetermined type.
At compile time you have no idea what the parameters will be, or how many there are.
This is a great use for an array of Pascal variants, If your subroutine thinks the format string will call for an Integer, double or string, it can access argv[ 0 ] as an Integer, double or string, and cycle through until it has accessed all Length( argv ) parameters (0.. Length( argv) - 1 ).
If you think it would be convenient to use format() or one of the many visual components with EWB, have a gander at my library.