Forum > Beginners
[SOLVED] Procedure parameter with no type?
MarkMLl:
--- Quote from: Joanna from IRC on November 27, 2024, 09:51:56 am ---I used to do things like that so that I could use one procedure for different types of parameters. Are you able to see the inner workings of the procedure with untyped parameter?
I remember having code to test what parameter was and typecast it inside of the procedure...
--- End quote ---
That sort of thing is best avoided if at all possible, since you're bypassing the type checks that make Pascal worth having.
If the parameter is a descendant of TObject (i.e. an instantiated class) then you can find out what the actual class is, but there's no "what type is this?" functionality in the basic (i.e. pre-OO) language. Even if you are using objects, I don't think you can easily use a case statement.
You can obviously use polymorphic functions, but there you are at the mercy of Pascal's sloppy implicit type conversions (which, as I've said before, Wirth tightened up in later languages). But a better solution is to use variant records where possible, together with careful consideration of where parameters can be declared const to reduce the amount of stuff copied around.
The implementation of procedures with untyped parameters, like the implementation of direct pointer manipulation, should be kept out of the hands of inexperienced programmers or at the very least subject to careful code review and testing.
MarkMLl
marcov:
The classic examples of untyped variables are the blockread/blockwrite examples that allow to pass records and (static) array directly to it, to read into.
The problem with untyped var is that there is no meta data. You don't get the size that is passed, so there usually is an extra parameter from which to derive size or type
Navigation
[0] Message Index
[*] Previous page