Solved

Using Arrays in class TObject in Delphi

Posted on 2014-04-10
3
1,622 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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