I am migrating some code that has its roots in a COBOL routine written over 40 years ago. The COBOL definition of the area of interest was:
01 TRACE-LINE PIC X(114).
01 FILLER REDEFINES TRACELINE.
02 TRACE-HEADER PIC X(18).
02 TRACE-ALPHA OCCURS 8.
03 TRACE-NUM PIC Z(9)9BB.
03 TRACE-AMT REDEFINES TRACE-NUM PIC Z(7)9.99B.
This gave me space (in TRACE-HEADER) to have a date & time area (only 2-digit years - this was early 1980's, and Y2K had not yet been invented), and an array of 8 areas each of which could contain a number, an amount or 12 associated characters (including dates).
By virtue of being able to MOVE SPACES to a group item, I could clear TRACE-LINE in one fell swoop. Then, I could use which ever of the areas I wanted to trace different values. It was pretty rudimentary, but I was able to pass it in and out of differrent sub-programs, and get a consistent trace result.
About 25 years ago I ported it to VBA, and extended the number of procedures available, to include conditional tracing (based on the relationship of a passed TraceLevel to a established TraceLevel, and to trace specific things for a Form Event, a Class Method and so on. This required a bit of extra effort, but again - the trace was easily available, and useful in the testing and debugging phase of developing a program. (It has shown up, unheralded, in some of my posts). Since then I've had a fairly easy conversions to other languages, and it's now time to see if I can port it to Lazarus.
I have two critical needs:
1) The ability to trace different data -types (Integers, Amounts, Real Numbers, strings etc), and
2) The ability to trace different numbers of these different data types.
From working with VBA I was familiar with Optional parameters, and Variant data types. However, in Lazarus, it seems that the way to have optional (ie a variable number of) parameters, is to overload procedures with differing numbers of parameters. This is ungainly (or at least, so it feels to me), but the real problem is that variable data-type can not be used with a default value. Fair enough, a variant can take any data-type, so how can we then specify a 'default' data type? Especially when there is a plethora of different meanings for the simple value 0
I hope this little exposition is clear, and understandable. What I'm trying to solve is either or both of the two presenting problems:
A) Is there a way (short of overloading almost,
ad infinitum, the various procedures that constitute the API) of allowing varying numbers of parameters to a procedure (or, of course, a function)?
B) Is there a way that a parameter can take on a different data-type at different invocations of the called procedure? IOW can I call Trace with parameter1 being an integer one time, and then being a date/time another time?
Having revealed my dinosaur like origins, I shall now resume a somnolent posture, and hope for some smarter heads than mine to offer some ideas!
Thanks,
Tony