Solved

how to initialize array(again)

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

813 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

17 Experts available now in Live!

Get 1:1 Help Now