Solved

how to initialize array(again)

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

14 Experts available now in Live!

Get 1:1 Help Now