An array of objects

[ Delphi Forum ] [ Delphi Tutorials -- by DelphiLand ]

Posted by Rhy on May 29, 2003 at 09:27:39:

I'm working on an interpreter/debugger for a knd of assembly language. I have made a container class called Tinstruction, which holds a string, an integer and an array of strings...

Now, when I read in the instructions from the user's file (the assembly source) I want to place each instruction into an instruction object. To do this, I have a dynamic array of Tinstruction (to hold all the instructions from the source), and another, static, array to hold all the valid instructions in the set (of which there are 24). The instruction set array is declared as follows:

instSet: array[0..23] of Tinstruction;

And the first thing I have the program do when it starts is to go through each element of the array, setting them to a unique, valid instruction.

The problem is, what I seem to have created is an array where every single element points to the one Tinstruction object, meaning whenever I assign an element with a value, all the other elements are going to hold the same information, as they all point to the same object.

What on earth have I done here?
How does delphi handle arrays of objects when it comes to constructing them? Do I need to construct each element of the array, one at a time?

There must be something obvious I'm missing (because if it's not obvious, it's going to be painful. :-)


Related Articles and Replies:

[ Delphi Forum ]
[ DelphiLand: free Delphi source code, tips, tutorials ]