Isn't there any (presumably non-standard) way of dereferencing Pointer variables? The reason I ask is because I need information on the type of variable whose address a Pointer variable contains. Said type will vary, and cannot be known until runtime.
If that can't be done, then could somebody please give me tips on writing generalized subroutines for reading and writing typed files?
Or should I just skip both of these and just write an interface object, and implement read/write mechanisms for each structure I intend on keeping in a stream? I'd rather avoid this (for it beats the whole point of OO, IMO), but I'd do it if it can't be avoided.
TIA.
[Hrm... Or maybe I'll do it in Ada, with generics. But, aside from knowing Pascal which is from the same family, I know nothing of Ada.]
Neil Santos wrote:
Isn't there any (presumably non-standard) way of dereferencing Pointer variables? The reason I ask is because I need information on the type of variable whose address a Pointer variable contains. Said type will vary, and cannot be known until runtime.
Could you give a code example of what you are trying to do?
Or should I just skip both of these and just write an interface object, and implement read/write mechanisms for each structure I intend on keeping in a stream? I'd rather avoid this (for it beats the whole point of OO, IMO), but I'd do it if it can't be avoided.
... and a code example for that solution, too? I don't quite understand what you mean here. What methods should that interface object have, and where/how do you want to call them?
Yours,
Markus
Neil Santos wrote:
Isn't there any (presumably non-standard) way of dereferencing Pointer variables? The reason I ask is because I need information on the type of variable whose address a Pointer variable contains. Said type will vary, and cannot be known until runtime.
Untyped pointers don't store the type, so you have to do yourself any work necessary to keep track of the type. (I suppose you mean untyped pointers since you wrote `Pointer' in upper-case. Otherwise, typed pointers can be dereferenced with `^', but I suppose you know that.)
Depending on your needs you might be able to use variant records, schemata or objects and avoid using untyped pointers (recommended whenever possible).
If that can't be done, then could somebody please give me tips on writing generalized subroutines for reading and writing typed files?
I don't quite understand. Typed files are, as the name says, typed, so you can't store "untyped" things in them. Again, variant records may help. (Schemata and objects are more tricky in files.)
For untyped files, check out `BlockWrite' etc.
Or should I just skip both of these and just write an interface object, and implement read/write mechanisms for each structure I intend on keeping in a stream? I'd rather avoid this (for it beats the whole point of OO, IMO), but I'd do it if it can't be avoided.
I don't quite understand. Are you using objects already? Then you shouldn't need untyped pointers at all since you have polymorphism.
It might help if you described what you're actually trying to achieve. If the question is about storing objects in files, we could explain some things (which maybe can be found in the archives, but at least not recently AFAIR).
Frank