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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:15:36+00:00 2026-05-20T12:15:36+00:00

If I wanted to declare a static compile-time array of Byte, I could do

  • 0

If I wanted to declare a static compile-time array of Byte, I could do it like this:

var
  bytes :array[0..24] of Byte = (1, 2, 3, .... );

However, the type of that is array[0..24] of byte, not System.TArray<System.Byte>, which is more commonly known as TBytes.

What I need is something that can be of type TBytes but I don’t want to have to add an initialization section to hold these byte values in some painful way:

var
    bytes2:TBytes;
initialization
    SetLength(bytes2,24); 
    bytes2[0] := 1; bytes2[1] := 2; ....

Is there some way to do this instead:

var
    bytes2:TBytes = (1,2,3, .... );

I tried also to find a way to convert quickly from TBytes (System.TArray<System.Byte>) and array[0..24] of Byte, like this:

 bytes2 := byte;

Unfortunately, the closest I can get is this brute-force code:

  SetLength(bytes2,Length(bytes));
  for n := 0 to Length(bytes) do begin
     bytes2[n] := bytes[n];
  end;

It seems to me for two types so closely related, that the compiler could do a little better job of allowing me to coerce or copy, from the one type to the other. Anybody else feel that way about various types of “Array of X”? Know any cool ways around it? If the compiler did some magic, it might make the Move(…) function work for this case, but Move actually gives you an access violation, and can’t be used with dynamic arrays or generic collections.

  • 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-20T12:15:36+00:00Added an answer on May 20, 2026 at 12:15 pm

    How about:

    var
      bytes: TBytes;
    begin
      bytes := TBytes.Create(1,2,3, .... );
    end;
    

    That said I always find it limiting that this syntax does not accept open arrays. So I have a bunch of functions that look like this:

    function Bytes(const A: array of Byte): TBytes;
    var
      i: Integer;    
    begin
      SetLength(Result, Length(A));
      for i := low(Result) to high(Result) do
        Result[i] := A[i];
    end;
    ...
    var
      b1, b2: TBytes;
      b3: array of Byte;
      b4: array [0..42] of Byte;
    ...
      b1 := Bytes(b2);
      b1 := Bytes(b3);
      b1 := Bytes(b4);
      b1 := Bytes([1,2,3,4]);
    

    I believe that the various generics enhancements in XE mean that this could be done with generics and without duplicating routines like Bytes for each different scalar.

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

Sidebar

Related Questions

I wanted to do something like this: <asp:Label ID=lblMyLabel onclick=lblMyLabel_Click runat=server>My Label</asp:Label> I know
I wanted to use the var keyword to declare a field in my class
I wanted some of those spiffy rounded corners for a web project that I'm
I want to use CodeDOM to both declare and initialize my static field in
Wanted to convert <br/> <br/> <br/> <br/> <br/> into <br/>
Wanted to get some consensus around a UI feature I'm working on right now.
I wanted to show the users Name Address (see www.ipchicken.com ), but the only
I wanted to emulate a popular flash game, Chrontron, in C++ and needed some
I wanted to generate one fix view using interface builder, but the size of
Just wanted to get an idea for ways (web) developers get round the short

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.