2

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!

15
  • Add a signature into your records.
    – LU RD
    Commented Oct 14, 2013 at 14:50
  • BTW, it should be possible to circumvent the inability to declare forward record references by using record helpers.
    – LU RD
    Commented Oct 14, 2013 at 14:55
  • Yes, record helpers are the way I get around this issue. Commented Oct 14, 2013 at 14:55
  • Yes, indeed record helpers do work, but there are two drawbacks: 1) You need to reference another Unit (with the helper methods) 2) XE2 Intellisense does not pickup helper methods. According to David's answer on another question this seems to be tackled in XE5. At the end I think I will stick with helper methods as well.
    – santiagoIT
    Commented Oct 14, 2013 at 15:07
  • 1
    @DavidHeffernan thanks so much for the pastebin. It is now very clear how you organize your code.
    – santiagoIT
    Commented Oct 14, 2013 at 17:06

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.