Advent of Code 2024

@sglienke

Can Spring4D save me from this ?

I just see a bunch of static arrays - how does spring4d come into play here?

The bottom line doesn’t work, and I want a short, elegant way to initialise the array.

Ah yes, that issue - typed const are no real const for the compiler and thus cannot be used in const array. You need to declare those directly in steps3.

You almost gave me hope … but no, I did try this. :frowning:

You might want to try const instead of var.
I am too lazy to type it out myself if you only post pictures with code :wink:

1 Like

Yes. I had tried const before I posted it

I need var for the working code with the initialisation deleted … so you get var. :slightly_smiling_face:

{$WRITEABLECONST ON} :smirk:

But yes, variable initialization when it comes to arrays and records is terrible in Delphi :frowning:

You can use a combination of type, const and var:

type TTuples = array[TDirection] of TupleInt;
const TupleInits: TTuples = ( (fst: ; snd: ), (...) );

var step: TTuples := TupleInits;
// Edit1: Or using type inference: var step := TupleInits;
// Edit2: And then you could also omit the type and just use:
// const TupleInits: array[TDirection] of TupleInt= ( (fst: ; snd: ), (...) );
// var step := TupleInits;
...

Ok ! Hell yeah. Thank you @Jarrod.

It hadn’t occurred to me to think of this, like in the way you might need to define a definite type to use in a function signature. :sparkles: :fire:

:tada: