How can I declare an array object field in Delphi? -


i tried got error in constructor.

e2029 'of' expected '[' found

dish = class  public     dish_name: string;             dish_id: integer;              dish_number: integer;          dish_units: string;             dish_price: integer;           dish_prime_cost: integer;      dish_ingredients_id: array[1..100] of  ingredients;  constructor create( newdish_name: string;     newdish_id: integer;  newdish_number: integer;     newdish_units: string;  newdish_price: integer;     newdish_prime_cost: integer;     newdish_ingredients_id:array[1..100] of  ingredients);    destructor destroy; end; 

ingredients class.

you cannot declare static array inline parameter. need declare type:

type   tingredientsarray = array[1..100] of ingredients; 

and use type both field , argument.

however, statically sized array not best choice. if need more 100 ingredients? if need 1, forced pass around 100? code stands, how can dish class know how many ingredients have been provided?

consider using dynamic array instead.

you should think lifetime , ownership of these ingredient objects. pass objects dish class. assume ownership? is, responsible destroying ingredient objects? if use value type ingredients, record, might find makes lifetime management simpler.

it idiomatic use zero-based indexing arrays in delphi. dynamic arrays zero-based. standard collection classes zero-based. if start using one-based arrays experience says going store confusion in future.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -