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?
DelphiPascal

Avatar of undefined
Last Comment
fischermx
SOLUTION
Avatar of Emmanuel PASQUIER
Emmanuel PASQUIER
Flag of France image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of fischermx
fischermx
Flag of Mexico image

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.
Avatar of Geert G
Geert G
Flag of Belgium image

epasquier
>> why not TCollectionItem for group

You could set extra properties on a group:
Default_profit_Margin
Default_Stock_Location
Default_Supplier
etc etc
Avatar of fischermx
fischermx
Flag of Mexico image

ASKER

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.
Avatar of Geert G
Geert G
Flag of Belgium image

why not use a database ?

much easier, you can copy a database, then mess with it ... :)
Avatar of Geert G
Geert G
Flag of Belgium image

loading data in design time ???
wooo ... you're adding a complexity level, which you will not like
Avatar of fischermx
fischermx
Flag of Mexico image

ASKER

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.
Avatar of fischermx
fischermx
Flag of Mexico image

ASKER

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
Avatar of fischermx
fischermx
Flag of Mexico image

ASKER

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.
Avatar of fischermx
fischermx
Flag of Mexico image

ASKER

Thank you!
Delphi
Delphi

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

60K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo