What is the syntax for declaring an index variable in a Delphi 2007 Pascal initialization block?

I need to initialize also arrays in the Delphi initialization block.

It looks like you cannot use the var block in the initialize block because it will not compile:

initialization
var
idx : Integer;
begin
    for idx := 0 to length(LastState)-1 do begin
        LastState[idx] := $FFFF;
    end;
end;

(The first compilation error complains about var):

([DCC Error] ScheAutoInfRb2.pas (6898): E2029 The expected expression, but 'VAR' found)

This will not compile (since idx is not declared):

initialization

    for idx := 0 to length(Last_Pro2State)-1 do begin
        Last_Pro2State[idx] := $FFFF;
    end;

[DCC Error] ScheAutoInfRb2.pas (6899): E2003 Undeclared Identifier: 'idx'

I know that I can declare an indexer in the declaration of the main block, but it has several drawbacks:

  • The indexer declaration is separated from its use, but (which may be in a hundred lines), and

  • "".

+4
2

.

- , initialization:

procedure InitLastStateArray;
var
  idx : Integer;
begin
  for idx := 0 to length(LastState)-1 do begin
    LastState[idx] := $FFFF;
  end;
end;

initialization
  IntLastStateArray;

end.
+8

, , :

, , , implementation , initialization. , interface implementation: , , , . interface, , .

var
  idx : Integer;
initialization
  for idx := 0 to length(LastState)-1 do
    LastState[idx] := $FFFF;
end.

, D7 initialization, Delphi , ( ) .


idx , , , initialization, , . , , , , , . , , , .

+1

Source: https://habr.com/ru/post/1629940/


All Articles