Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using Arrays in class TObject in Delphi

Posted on 2014-04-10
3
Medium Priority
?
1,903 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 450 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

971 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