02.12.2018
Posted by 
Delphi Initialize Record Rating: 3,5/5 1754 votes

Hello everybody. How can I initialize an array of records, like # type # Example = record # id: integer; # content: string # end; # # var # # ExampleArray: array[1.N] of Example; Can I initialize the array in the 'var' section?

  1. Delphi Initialize Recorder
  2. Delphi Initialize Recording

I tried something like the following in Delphi, but it doesn't work: ExampleArray: array[1.N] of Example = ( (1, 'example 1'), (2, 'example 2')., (N, 'example N')); Can it be done? Probably my syntax interpretation is wrong, but I have no books at hand, and I don't want to do it in the main code, like ExampleArray[1].id:= 1; ExampleArray[2].content:= 'example 1'; etc. Any help would appreciated TIA ---------------------- Pierre Leon --------------------------- Wed, 18 Jun 1902 08:00:00 GMT.

Initialize must know the type of the buffer so it knows about array and record members. If you are casting a generic Pointer, be sure you cast it to the correct type. Typecasting pointers is a common source of hard-to-locate bugs.

Delphi initialize recordDelphi Initialize Record

Delphi Initialize Recorder

> # type > # Example = record > # id: integer; > # content: string > # end; > # var > # ExampleArray: array[1.N] of Example; > Can I initialize the array in the 'var' section? > I tried something like the following in Delphi, but it doesn't work: > ExampleArray: array[1.N] of Example = ( (1, 'example 1'), (2, 'example > 2')., (N, 'example N')); There is only one little thing you forgot (at least for BP, don't know Delphi): to declare a initialised record constant, you have to precede each field value by the field identifier, in your case: ExampleArray: ARRAY[1.N] OF Example = ( (id: 1; content: 'example 1').); Also, note the semi-colons separating the fields (instead of commas). Good luck, Remco -- Remco Vietor Department of Chemistry University of Glasgow Glasgow G12 8QQ U.K. Wed, 18 Jun 1902 08:00:00 GMT. >Hello everybody.

Delphi Initialize Recording

>How can I initialize an array of records, like ># type ># Example = record ># id: integer; ># content: string ># end; ># ># var ># ># ExampleArray: array[1.N] of Example; >Can I initialize the array in the 'var' section? >I tried something like the following in Delphi, but it doesn't work: >ExampleArray: array[1.N] of Example = ( (1, 'example 1'), (2, 'example >2')., (N, 'example N')); >Can it be done? Probably my syntax interpretation is wrong, but I have no >Pascal books at hand, and I don't want to do it in the main code, like >ExampleArray[1].id:= 1; >ExampleArray[2].content:= 'example 1'; >etc. >Any help would appreciated >TIA Hello you can initialize only CONST array and not that ones in the VAR section. The way you initialize the array above can be done only with CONST arrays. Bye Andrea Wed, 18 Jun 1902 08:00:00 GMT Page 1 of 1 [ 3 post ].