Link to home
Start Free TrialLog in
Avatar of fischermx
fischermxFlag for Mexico

asked on

How to declare a Constant array of array of Record in Delphi

Hi,

Let's suppose the following code, which is used as sample, that is to declare a Constant array of record:

type
    TShopItem = record
      Name : string;
      Price : currency;
    end;

const
    Items : array[1..3] of TShopItem =
    (
      (Name : 'Clock'; Price : 20.99),
      (Name : 'Pencil'; Price : 15.75),
      (Name : 'Board'; Price : 42.96)
    ) ;


What if I want to declare a to declare a Constant array of array of record (array of array).
How do I declare that?

Taking the previous classes, now suppose that I have "groups" of TShopItem's, like :

Group 1
      (Name : 'Clock'; Price : 20.99)
      (Name : 'Pencil'; Price : 15.75)

Group 2
      (Name : 'Board'; Price : 42.96)
      (Name : 'Eraser'; Price : 2.96)

Group 3 (note different length)
      (Name : 'Paper'; Price : 5.96)
      (Name : 'Pen'; Price : 2.96)
      (Name : 'Postits'; Price : 2.96)

How do I put all that in a single constant array of array declaration?
SOLUTION
Avatar of Emmanuel PASQUIER
Emmanuel PASQUIER
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fischermx

ASKER

epasquier:

Thanks for your answer. But I think I can't do that. In the real application some groups have two or three elements, some others have 20 or 25, so there are a lot of gaps.
epasquier
>> why not TCollectionItem for group

You could set extra properties on a group:
Default_profit_Margin
Default_Stock_Location
Default_Supplier
etc etc
Geert_Gruwez:

That was, of course, sample data that I took from somewhere.
The real application will store REAL CONSTANT values that will never  ever change.

I like the TCollection idea, though this data has to be available at design time.... mmh..... I guess I can fill the collection at the initialization in the property editor unit (?).

Thanks for your answer.
why not use a database ?

much easier, you can copy a database, then mess with it ... :)
loading data in design time ???
wooo ... you're adding a complexity level, which you will not like
epasquier:

I like your idea of having a group, and a groups collection, besides the items.
I think I will use that.

My only concern is how to make all those available at design time for my property editors.
Geert_Gruwez:

>why not use a database ?
>much easier, you can copy a database, then mess with it ... :)

LOL, I want to do this to avoid the use of a database.
Yes, I know that's the proper place for so much data, but I can't.
It will be used at design time to fill some property editors.

I thought about to use a resource file, but not sure how if that will be even messier.



> My only concern is how to make all those available at design time for my property editors
I don't see why you couldn't create your own property editor based on this principle to make it easy for the programmer to fill that structure at design time. Just have to find  a persistent way of storing all that information (like exporting in a string). I'm not that used to make property editors, but if I remember, Geert have more experience about it and would be glad to learn also :o)

Or he is not listening, and I will have to dig tomorrow for a solution
epasquier:

That's fine. I think I will just have to create those objects in the initialization to have them loaded and ready for when the property designer is called.
It has to work, I guess.
Thank you!