Delphi Array Constants

Posted by admin
Delphi Array Constants Average ratng: 6,9/10 3590 votes

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). Minecraft pocket edition free on computer. 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? You cannot because the groups 1, 2 & 3 do not have the same size, so you cannot declare a single array. Or you declare an array of 3x3 and there will be some holes (unused elements) const Items: array[1.3, 1.3] of TShopItem = ( ( (Name: 'Clock'; Price: 20.99), (Name: 'Pencil'; Price: 15.75), (Name: 'Board'; Price: 42.96) ), ( (Name: 'Paper'; Price: 5.96), (Name: 'Pen'; Price: 2.96), (Name: 'Postits'; Price: 2.96) ), ( (Name: 'Clock'; Price: 20.99), (Name: '-'; Price: 0), (Name: '-'; Price: 0) ) ); Select all. A constant for a price?

Delphi Const Array Of Tpoint

An open array may also be defined with const value type. This is called a Variant open array - it is mostly used to allow a variable number of argument value to be passed to a subroutine. In order to pass a Dynamic array by reference, the array and the subroutine definition of the array must be via an array type definition.

Isn't that a completely wrong approach? I have never known a price to be constant (only for a day. Spb mp3 songs download. And then still.) i would come for Petrol at your place.

Especially if your shop would have existed 50 years ago. About the idea. Why not use a TCollection to hold the items and a TCollectionItem to contain a specific item type TShopItem = class(TCollection) private fPrice: Double; fName: string; fGroup: string; // single group or multiple group??? You consider create a TCollection Group too:) public property Name: string read fName write SetName; property Price: Double read fPrice write SetPrice; property Group: string read fGroup write SetGroup; end; TShopItems = class(TCollection) end; at the start of your program: procedure InitTestData; procedure AddItem(aName: string; aPrice: double; aGroup: string); begin with ShopItems.Add do begin Name:= aName; Price:= aPrice; Group:= aGroup; end; end; begin AddItem('Clock', 20.99, 'Group 1'); AddItem('Pencil', 15.75, 'Group 1'); AddItem('Board', 42,96, 'Group 2'); end.

Delphi

> 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.