Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to initialize array(again)

Posted on 1998-07-18
5
Medium Priority
?
283 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 150 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

971 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