Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1058445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:01:45+00:00 2026-05-16T18:01:45+00:00

I am trying to create a function with a variant record-type parameter that allows

  • 0

I am trying to create a function with a variant record-type parameter that allows inline-casting or assignment, as such:

type rectype = ( VT_INT, VT_CHAR, VT_BOOL );
     rec = record
       case t : rectype of
         VT_INT  : ( i : integer );
         VT_CHAR : ( c : char );
         VT_BOOL : ( b : boolean );
     end;

procedure handler( r : rec );
begin
  case r.t of
    VT_INT  : { do something with r.i }
    VT_CHAR : { do something with r.c }
    VT_BOOL : { do something with r.b }
  end;
end;

Now, the above “works” fine, as long as you take the time to do set up the variable manually, as such:

 r.t := VT_INT;
 r.i := 42;
 handler( r );

But, I would like to abuse the typing system a bit, and attempt to do it inline (I’ll explain why in a moment), along the lines of:

 handler( rec( VT_INT, 42 ) );

A helper function would be fine, as well, and I’ve tried a couple of different methods to do this, which can be seen here (for brevity of this post):

http://pastie.org/private/glxhwbpsbbh5gtxju0uvxa

Now, for the reason: I am working on, and have indeed released a unit testing suite that is aiming to be as portable as Pascal itself (builds under FreePascal and Turbo Pascal 7 (yes, really)). I’ve already publicly released the open-source software (can’t link yet, not enough rep), which include different functions for different types: isI(), isR(), isS(), isP(), isC(), etc. This repeats a lot of code, and I know there is a better way to do this. I believe there is a variant type supported by FPC and Delphi, which I can use via IFDEF directives on those platforms, but the real clincher is TP7, which I still want to support for obscene reasons.

The reason that 4 lines per function call to set up the record isn’t really feasible is that as this is the user-facing API, and making testing that convoluted will just mean that no one will do it. A test set with the current API is straightforward with a single function call to perform each test, and I just hope it’s possible to turn all of the several type-specific functions into something like:

is( VT_INT, SomeIntFunc( v ), 42, 'Test Name' );

I am willing to go to great lengths to circumvent typing under TP7, including manipulating the stack myself in assembly, etc. But I’m hoping a modified version using syntax I’m just not familiar with will do the job.

So, old-school Pascal programmers (I know there must be some out there), any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:01:45+00:00Added an answer on May 16, 2026 at 6:01 pm

    Free Pascal is no problem, since it supports Delphi constructs like (custom) variants, array of const interfaces and other tricks to deal with runtime typing (as long as it is limited to a overseeable number). Recent Delphi’s and FPC support generics, and you could probably go a long way duplicate “boost” with it.

    Doing it TP old school however is the hard part. It simply has nearly no untyped (or better: runtime typed) functionality.

    The only thing I can think of is

     procedure rec(vartype:Ttypeofvar;var value):tvariantrecord;
     begin
       rec.t:=vartype
       case vartype of 
          vt_int: move (value,@rec.i,sizeof(integer));
          ..
          ..
     end;
    

    A working workaround, but not typesafe, since passing rec(varint,”something double”) is possible. TP simply doesn’t have much to work with, except the VAR formal parameter.

    At this point you really have to ask yourself if crippling your frameworks for TP7 is really worth it. It has been dead for 16 years now. Let it rot in peace.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 536k
  • Answers 536k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Is this what you're looking for? http://manual.macromates.com/en/working_with_text 4.5.2 Find Clipboard… May 17, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Here is how you disable the month selection arrows...a total… May 17, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Unfortunately that type of information isn't available in the collection.… May 17, 2026 at 1:19 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am trying to create a small function that returns the number of spaces
I am trying to create a jquery accordion that fades the header of the
I am trying to create a UDF that does 2 different things depending on
Im trying to create a function to check for a substring within a string
I am trying to create a function to find the square root of a
I am trying to create a function which, When given an object will output
I'm trying to map OleDb parameters to an Oracle Function. I was able to
I'm trying to create a Delphi version of this algorithm: void PWSfileV3::StretchKey(const unsigned char
ok so I am trying to dynamically create a select list using javascript, basically
Trying to understand why you can't use sql_variant for the value type when using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.