Solved

how to initialize array(again)

Posted on 1998-07-18
5
274 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now