Solved

Using Arrays in class TObject in Delphi

Posted on 2014-04-10
3
1,420 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
Comment Utility
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
Comment Utility
Many thanks Thommy, I will give it a go.
0
 

Author Comment

by:magman5
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

13 Experts available now in Live!

Get 1:1 Help Now