Dynamic Type array 
Author Message
 Dynamic Type array

: I need to create a variable number of objects at runtime.
: ...
:   Items : Array[1.. Table.recordcount] of object
:
: Can anyone help ?? My next thought is to use Pointers !! any thoughts ?

Create your objects dynamically and store the pointers to them in a TList
object. You will be able to handle them like an array. Read the online-help
for TList. If you want (or need) i could send you a piece of code that does
it.

hope it helps ... bernd

--
.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.


D-89075 Ulm
.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.,.



Mon, 16 Feb 1998 03:00:00 GMT  
 Dynamic Type array
I need to create a variable number of objects at runtime.

For example if I had a table which contained a variable number of food
items and wanted the user to check off items according to some criteria.
 I would want to create a dynamic form that places one checkbox for each
item on a form.    In VB (which I am trying to leave behind) the
programmer can create an array and then REDIM that array to the needed
number.  Since this is not allowed in a compiled lang I thought I should
be able to do the following

  Items : Array[1.. Table.recordcount] of object

This wont compile because table.recordcount can not be evaluated to a
const at compile time. I have even tried four or five ways to 'Trick'
Delphi without success,  Dooooo !!!!

Can anyone help ?? My next thought is to use Pointers !! any thoughts ?

any help would be greatly appreciated.
thanks

Shannon Hanson



Mon, 16 Feb 1998 03:00:00 GMT  
 Dynamic Type array

Quote:
>Can anyone help ?? My next thought is to use Pointers !! any thoughts ?

Your getting close to the answer. In fact I have seen this question posted in
one form or another by many.

You have the option of using the TStringList component where you can
dynamically add objects that you may wish to use -- whether these are
components (buttons, text boxes or other) is unimportant. For example you
would call >> AddObject('SomeName', TObject.Create).

Another option is to create your own unidirectional linked list of TObjects.
In fact that is what TStringlist is doing. Go back to your old Turbo Pascal
books -- some have great examples on linked lists.

By the way never forget that Object Pascal treats all Objects as pointers.



Tue, 17 Feb 1998 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Help! array of type array

2. Dynamic matrix type?

3. Dynamic Filter on TCustomADODataset where filter field data type change

4. Variable/Dynamic Data Type Implementation

5. dynamic array

6. Dynamic array in database

7. How to store dynamic array to memofield?

8. Dynamic Array puzzle

9. How to declare dynamic array in fpc ??

10. dynamic arrays

11. Memory access; relative position (dynamic array)

12. Heap error while allocating dynamic array in protected.

 

 
Powered by phpBB® Forum Software