Reputation: 9431
I am using Delphi XE2. As a workaround to Delphi not supporting forward references to Record types I started using untyped parameters.
How can I obtain the Type of an untyped Parameter?
procedure TSomeRecord.TransformBy(const AUntypedParam);
begin
// how can I ensure that **AUntypedParam** is of a specific record type?
I need to make sure that AUntypedParam is of a specific type, otherwise an exception should be thrown. Thank you!
Upvotes: 2
Views: 344
Reputation: 613461
How can I ensure that
AUntypedParam
is of a specific record type?
You cannot. That's pretty much the modus operandi of untyped parameters. When you say to the compiler, don't check the type of the actual parameter, the compiler takes you at your word and lets you pass anything that you like. You cannot have it both ways.
@LURD astutely points out that you can use record helpers to work around this compiler limitation. I do hope that somebody from Embarcadero reads questions on Stack Overflow. This must be the third or fourth time in the past week that we've had a question due to the limitations of extended records.
Upvotes: 2