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 8813697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:55:22+00:00 2026-06-14T03:55:22+00:00

It is possible to create a function which accepts variable number of arguments: function

  • 0

It is possible to create a function which accepts variable number of arguments:

function f(const x: array of const): String;

and use it this way:

f([1,3,4, "hello"]);

It is also possible to define an argument as “changeable”:

function g(var x: Byte): String;

var B: Byte;
g(B);

But is it possible to define a function which can take any number of arguments of whatver type and change all of their values?
I know I can do this using pointers but then I don’t know the type of the parameter passed so it is quite unsafe to mess with them.


I just want to create a function which can return variable number of variables of many different types, not just of 1 type or just 1 variable. And I don’t want to write zillions of lines to use the function- it should just be the function itself, no SetLength() before the function call or anything. So here is the best thing I made so far:

type TVarArr = Array of Variant;
     PVarArr = ^TVarArr;
Procedure f(a: PVarArr);
var
 i:Integer;
begin
  SetLength(A^, 4);
  a^[0] := 46;
end;

ar: TVarArr;
begin
f(@ar);
caption := IntToStr(ar[0]);
  • 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-06-14T03:55:23+00:00Added an answer on June 14, 2026 at 3:55 am

    Tom will not be able to use this answer as his Delphi version isn’t high enough, but anybody on D2010 or higher will be able to put the extended rtti’s TValue to good use on this type of challenge.

    Following is a small console app showing how to:

    • create a dynamic array of TValue’s from a open array parameter;
    • copy a dynamic array of TValue’s to a new dynamic array modifying individual values on the way;
    • modify the items in a dynamic array of TValues “in place”.

    Enjoy.

    program Project1;
    
    {$APPTYPE CONSOLE}
    
    {$R *.res}
    
    uses
      System.Rtti,
      System.SysUtils,
      System.TypInfo;
    
    const
      StringKinds: set of TTypeKind = [tkChar, tkString, tkWChar, tkLString, tkWString, tkUString];
    
    type
      TValueArray = array of TValue;
    
    function ValueArrayFromConstArray(const aSource: array of TValue): TValueArray;
    var
      idx: Integer;
    begin
      SetLength(Result, Length(aSource));
      for idx := Low(aSource) to High(aSource) do
        Result[idx] := aSource[idx];
    end;
    
    function ReturnNewArray(const aSource: TValueArray): TValueArray;
    var
      idx: Integer;
    begin
      SetLength(Result, Length(aSource));
      for idx := Low(aSource) to High(aSource) do
        if aSource[idx].Kind in StringKinds then
          Result[idx] := 'Dest' + aSource[idx].ToString
        else
          if aSource[idx].Kind in [tkInteger] then
            Result[idx] := 10 + aSource[idx].AsInteger
          else
            Result[idx] := aSource[idx];
    end;
    
    procedure ModifyArrayValues(var aArray: TValueArray);
    var
      idx: Integer;
    begin
      for idx := Low(aArray) to High(aArray) do
        if aArray[idx].Kind in StringKinds then
          aArray[idx] := 'Dest' + aArray[idx].ToString
        else
          if aArray[idx].Kind in [tkInteger] then
            aArray[idx] := 10 + aArray[idx].AsInteger
          else
            ;//aArray[idx] := aArray[idx];
    end;
    
    var
      Source: TValueArray;
      Destination: TValueArray;
      Item: TValue;
      idx: Integer;
    begin
      Source := ValueArrayFromConstArray(['Some', 42, TObject]);
      Destination := ReturnNewArray(Source);
      idx := 0;
      WriteLn('', #9, 'Old', #9, 'New');
      WriteLn('-', #9, '----', #9, '----');
      for Item in Source do
      begin
        WriteLn(idx, #9, Item.ToString, #9, Destination[idx].ToString);
        Inc(idx);
      end;
      WriteLn;
      WriteLn;
      WriteLn('', #9, 'Modified');
      WriteLn('-', #9, '----');
      Source := ValueArrayFromConstArray(['first', 50, TValue.From<TFloatValue>(fvCurrency)]);
      ModifyArrayValues(Source);
      for Item in Source do
      begin
        WriteLn(idx, #9, Item.ToString);
      end;
      ReadLn;
    end.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to create a SQL Server function which returns a nullable string?
Is it possible to create a template function that takes a variable number of
Is it possible to create a function which accepts it's parent object as a
Possible Duplicate: C Macros to create strings I have a function which accepts one
In jQuery is it possible to create a function that sets a variable which
In C++11 it is possible to create a function which returns the size (number
Is it possible to create a function which takes a pointer to another function?
I would like to create a function which can take two arguments object and
I'm trying to create a boolean recursive function which accepts 1 parameter only and
I'm trying to create a templated function which accepts an iterable and a function,

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.