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

  • SEARCH
  • Home
  • 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 1085485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:41:43+00:00 2026-05-16T22:41:43+00:00

Is there a standard way to convert between TVarRec and Variant values? I want

  • 0

Is there a standard way to convert between TVarRec and Variant values?

I want to parse an ‘array of const’ and use the values to populate parameters in a TMSQuery. To do this I’m using a list of column names (generated from TMSQuery.KeyFields), and matching the values in the array with the column names in KeyFields (by position), then using the column name to set the corresponding parameter using ParamByName.

The code below is what I’ve come up with, but VarRecToVariant doesn’t seem very elegant. Is there a better solution?

  keyFields: TStringList;
    // List of table column names (keyFields.DelimitedText := query.KeyFields;)
    // e.g. Name, Age
  query: TMSQuery;
    // Parametrized query with a parameter for each field in keyFields 
    // SELECT * FROM People WHERE Age=:Age AND Name=:Name

  // If keyValues is ['Bob', 42] the resulting query should be
  // SELECT * FROM People WHERE Age=42 AND Name='Bob'

  procedure Read(keyValues: array of const);
  var
    i: Integer;
    name: string;
    value: Variant;
  begin
    ...
    for i := 0 to keyFields.Count - 1 do
    begin
      name := keyFields[i];
      value := VarRecToVariant(keyValues[i]);
      query.ParamByName(name).Value := value;
    end;
    query.Open
    ...
  end;

  function VarRecToVariant(varRec: TVarRec): Variant;
  begin
    case varRec.VType of
      vtInteger:    result := varRec.VInteger;
      vtBoolean:    result := varRec.VBoolean;
      vtChar:       result := varRec.VChar;
      vtExtended:   result := varRec.VExtended^;
      vtString:     result := varRec.VString^;
      ...
    end;
  end;

Notes:

  • The values in the array of const depend on the parameters in the query. The caller knows what these are, but the method that uses the array doesn’t know how many or what type to expect. I.e. I can’t change the method to Read(name: string; age: integer).
  • The parameters are not necessarily used in the same order that the values are specified in the array of const. In the example, keyFields are specified as “Name,Age” but the query uses Age before Name. This means Params[i].Value := keyValues[i] won’t work. I think VarRecToVariant would still be needed anyway, which I’m trying to avoid).
  • 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-16T22:41:43+00:00Added an answer on May 16, 2026 at 10:41 pm

    Replace

    procedure Read(keyValues: array of const); 
    

    with

    procedure Read(keyValues: array of Variant); 
    

    Then you will not need to convert TVarRec to Variant.

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

Sidebar

Related Questions

Is there a standard way / C# library to convert a string into a
Is there a standard way to convert the localizable.strings file to csv format, or
Is there a standard way in .NET/C# to convert a datetime object to ISO
Is there a standard way to convert an XSD to an input form (ASP.NET
Is there any standard / boilerplate way to convert SQL uniqueidentifiers into the same
Is there a standard way in Ocaml, to convert from (for example) a\n (a
Is there any standard way of debugging Javascript on a webpage that's being accessed
is there a standard way to encode the user location (country, state/region, town), so
Is there a standard way of maintaining a weak pointer to a parent (which
Is there a standard way to access the underlying container of stack , queue

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.