Solved

Using Arrays in class TObject in Delphi

Posted on 2014-04-10
3
1,468 Views
Last Modified: 2014-04-11
I wish to use a set length array of integers (or SmallInt) called MyObjects in my custom class called TGroup. These are indexes to other graphic objects as part of my drawing program.

The following will not compile in Delphi7. I don't understand why not. I believe TList may work, but I would have to convert strings to/from integers - not ideal. Suggestions please.

type


const
   max_objects_per_group = 100 ;
.....

   TGroup = class(TObject)
   private
      aName     : string ;  // eg Chair, Table, Vase
      aLayer    : integer ; // The layer the group belongs to
      aSelected : boolean ;
      atlx,atly,atlz : double ;  // group extremities
      abrx,abry,abrz : double ;
      acount  : longint ; // number of objects in group
      aMyobjects : array[1..max_objects_per_group] of SmallInt ; // -32,768 to 32,767
                            // List of object indexes.
                            // Can have groups within groups.
                            // a -ve index means it is another group
  public
     property Name      : string  read aName     write aName ;
     property Layer     : integer read aLayer    write aLayer ;
     property Selected  : boolean read aSelected write aSelected ;
     property tlx       : double  read atlx      write atlx ;
     property tly       : double  read atly      write atly ;
     property tlz       : double  read atlz      write atlz ;
     property brx       : double  read abrx      write abrx ;
     property bry       : double  read abry      write abry ;
     property brz       : double  read abrz      write abrz ;
     property MyObjects : array[1..max_objects_per_group] of SmallInt  read aobjects write aobjects ;
  end ;

Open in new window

0
Comment
Question by:magman5
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
Thommy earned 150 total points
ID: 39993463
This code compiles without any errors...

const
   max_objects_per_group = 100 ;


type

  TObjArrType=array[1..max_objects_per_group] of SmallInt;

   TGroup = class(TObject)
   private
      aName     : string ;  // eg Chair, Table, Vase
      aLayer    : integer ; // The layer the group belongs to
      aSelected : boolean ;
      atlx,atly,atlz : double ;  // group extremities
      abrx,abry,abrz : double ;
      acount  : longint ; // number of objects in group
      aMyObjects : TObjArrType; 
  public
     property Name      : string  read aName     write aName ;
     property Layer     : integer read aLayer    write aLayer ;
     property Selected  : boolean read aSelected write aSelected ;
     property tlx       : double  read atlx      write atlx ;
     property tly       : double  read atly      write atly ;
     property tlz       : double  read atlz      write atlz ;
     property brx       : double  read abrx      write abrx ;
     property bry       : double  read abry      write abry ;
     property brz       : double  read abrz      write abrz ;
     property MyObjects : TObjArrType  read aMyObjects write aMyObjects ;
  end ;

Open in new window

0
 

Author Comment

by:magman5
ID: 39993498
Many thanks Thommy, I will give it a go.
0
 

Author Comment

by:magman5
ID: 39993731
The above compiles fine. I am now having trouble storing data into the array

 
         aGroup := TGroup.Create ;  
...      

        aGroup.Count := 1 ; // is fine

       aGroup.MyObjects[1] := 123  ;  // compile error :  left side cannot be assigned to
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

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 76
URL for downloading Google Chrome for Win XP 2 122
Firemonkey android show image from resource ? 1 33
CheckListBox usage 3 51
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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

895 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