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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:48:04+00:00 2026-06-03T14:48:04+00:00

Can I initialize a constant dynamic array of arrays? If: type tNamePair = array[1..2]

  • 0

Can I initialize a constant dynamic array of arrays?

If:

type
  tNamePair = array[1..2] of String;
  tPairList = array of tNamePair;

How can I create an initialized constant? I can’t get the code below compile:

const
  PairList: tPairList = ( ('One', '1'), 
                          ('Two', '2'),
                          ('Three', '3'));

If that’s not possible, can a constant fixed array be initialized with a fixed array:

 type
    tPairList: array[1..3] of tNamePair;

If that’s not possible, can a constant dynamic array be initialized with a record:

tNamePair = record 
              English: String;
              Number: String;
            end;           
tPairList = array of tNamePair;

if that’s not possible can a constant fixed array be initialized with a record:

tNamePair = record 
              English: String;
              Number: String;
            end;           
tPairList = array[1..3] of tNamePair;

If that’s not possible, any suggestions other than just hardwiring assignments in the code, which frankly would have taken me less time than composing this question!

  • 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-03T14:48:09+00:00Added an answer on June 3, 2026 at 2:48 pm

    Prior to XE7 you could not create dynamic array constants. Constants have to be known at compile time, but dynamic arrays are allocated at runtime.

    A fixed array of fixed arrays can be declared at compile-time:

    type
      tNamePair = array[1..2] of String;
      tPairList = array[1..3] of tNamePair;
    
    const
      PairList: tPairList = ( ('One', '1'),
                              ('Two', '2'),
                              ('Three', '3'));
    

    A fixed array of records can also be declared at compile-time:

    type
      tNamePair = record
                  English: String;
                  Number: String;
                end;
      tPairList = array[1..3] of tNamePair;
    
    const
      PairList: tPairList = ( (English: 'One'; Number: '1'),
                              (English: 'Two'; Number: '2'),
                              (English: 'Three'; Number: '3'));
    

    If you need a dynamic array, you have to construct it at run-time. You can either build it up directly:

    type
      tNamePair = array[1..2] of String;
      tPairList = array of tNamePair;
    
    var
      PairList: tPairList;
    
    initialization
      SetLength(PairList, 3);
      PairList[0][1] := 'One';
      PairList[0][2] := '1';
      PairList[1][1] := 'Two';
      PairList[1][2] := '2';
      PairList[2][1] := 'Three';
      PairList[2][2] := '3';
    end.
    

    Or you can define a compile-time constant fixed array and copy it into the dynamic array at run-time:

    type
      tNamePair = array[1..2] of String;
      tPairList = array[1..3] of tNamePair;
      tPairListDyn = array of tNamePair;
    
    const
      PairList: tPairList = ( ('One', '1'),
                              ('Two', '2'),
                              ('Three', '3'));
    
    function MakePairListDyn(const Pairs: tPairList): tPairListDyn;
    var
      I, J: Integer;
    begin
      SetLength(Result, Length(Pairs));
      J := 0;
      for I := Low(Pairs) to High(Pairs) do begin
        Result[J] := Pairs[I];
        Inc(J);
      end;
    end;
    
    var
      Pairs: tPairListDyn;
    
    initialization
      Pairs := MakePairListDyn(PairList);
    end.
    

    For the situation post XE7 see @LURD’s answer.

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

Sidebar

Related Questions

Can I declare an int array, then initialize it with chars? I'm trying to
So I want to initialize an int 2d array very quickly, but I can't
When I running ruby I get the following warnings: ~/.gem/gems/psych-1.2.1/lib/psych.rb:93: warning: already initialized constant
We can initialize a container deque by using standard input like this: deque<int> c((istream_iterator<int>(cin)),(istream_iterator<int>()));
In c# I can initialize a List at creation time like var list =
There are several different ways I can initialize complex objects (with injected dependencies and
Using C# 3.0, we can initialize objects without their constructors for syntactical reasons. Such
How do I know when my GUI is ready, so I can initialize my
Can we initialize Python objects with statement like this: a = b = c
I would like to know: how can i initialize class object with parameters? I've

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.