[fpc-pascal] Correct syntax for initialized constants/variables
Ralf Quint
freedos.la at gmail.com
Fri Apr 28 07:52:11 CEST 2017
On 4/27/2017 12:22 PM, Ewald wrote:
> On 27/04/17 20:49, Ralf Quint wrote:
>> I try to include some initialized constants/variables in an application
>> of mine, but somehow stumbled upon a stupid little problem that I can't
>> figure out myself after nights on the computer.
>>
>> I see in the reference docs (section 4.4) examples for arrays and
>> examples for records, but in my case, I would need to properly define an
>> array of records.
> Something like this?
>
> Type
> TA = Record
> a: Integer;
> End;
>
> Var
> SomeArray: Array[0..1] of TA = (
> (a: 42;),
> (a: 17;)
> );
>
> Note: this is written from memory, syntax might differ a little (but the
> error messages from the compiler should help you out in that case).
Well, no, the error messages just state "expected this, found that",
without actually giving a REAL hint...
The declaration would be something like this
Type tStateRecord = Record
StateAbbrev : String [4];
StateName : String [40];
InLower48 : Boolean;
end;
tStateArray = Array [1..MaxNoStates] of tStateRecord;
Var {or Const, so it's initialized only once}
States : tStateArray = ( (StateAbbrev : 'AL', StateName :
'Alabama', InLower48:TRUE),
(StateAbbrev : 'AK',
StateName : 'Alaska', InLower48:FALSE),
...
);
Various versions of parenthesis just vary the error message, either the
above mentioned "expected this, found that" or "filed xyz not initialize"...
Ralf
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
More information about the fpc-pascal
mailing list