Solved

how to initialize array(again)

Posted on 1998-07-18
5
277 Views
Last Modified: 2010-04-04
Hello.  I want a question again.

    I want to know how to initialize array.

    (ex)
    type
    TForm1 = class(TForm)
    ..
    private
    ..
    public
    ..
    end;

    var
      arrayA: array[0..2] of Integer := (0,1,2);

    It's Ok.But when array is class member, compile error occurs.

    type
    TForm1 = class(TForm)
    ..
    private
    m_arrayA: array[0..2] of Integer := (0,1,2);
    ..
    public
    ..
    end;

    So I have to program as follows.

    type
    TForm1 = class(TForm)
    ..
    private
    m_arrayA: array[0..2] of Integer;
    ..
    public
    ..
    end;
    ..
    procedure TForm1.FormCreate;
    begin
    m_arrayA[0] := 0;
    m_arrayA[1] := 1;
    m_arrayA[2] := 2;
    end;

    This code is very ugly.
    I want to initialize array like C or Java.

    Please teach me a good method.

    Sakya




0
Comment
Question by:sakya
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
bome earned 50 total points
ID: 1358157
Initialize the array with a constant array:

1. constant array:
const arrayA_const: array[0..2] of Integer = (0,1,2);

2. Member array:
    private
     m_arrayA: array[low(arrayA_const)..high(arrayA_const)] of Integer;

3. Initialize in OnCreate:
move(arrayA_const,m_arrayA,sizeof(m_arrayA));

This is not *very* nice, but in my opinion the only way.

bome
0
 

Author Comment

by:sakya
ID: 1358158
Thanks bome.

This case is integer so this way is Ok.
But if I want to use Component array like array[0..2] of TEdit instead of integer,
What can I do?

Please teach me
0
 

Expert Comment

by:bome
ID: 1358159
hehe, in my knowledge this is not possible.
Actually, I do the "ugly" way very often, for the components. That is one of the rare things that is actually better in VB.

bome
0
 

Expert Comment

by:bome
ID: 1358160
for large amount of things like copy/paste I use Ultra Edit with a Macro.
bome
0
 

Author Comment

by:sakya
ID: 1358161
Thank you very much.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question