Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using Arrays in class TObject in Delphi

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

688 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