Home > Back-end > Delphi to local array variable assignment
Delphi to local array variable assignment
Time:09-18
A very simple question, why in Delphi pilot many method is not?
Function a (); Var B: array [4] 1.. of integer; The begin B:=(2,4,3,7);//b is a local variable array, and there is no law to assign data, how to b assignment? end;
The above b assignment would be an error, how to write the correct statement?
CodePudding user response:
[4] : b=250;
CodePudding user response:
Three kinds of methods: Var A: an array of integer=[1.. 4] (1, 2, 3, 4); B: an array of integer; C: TArray; I: integer; The begin For I:=1 to 4 do writeln (a [I]); B:=VarArrayOf ([2, 3, 4, 5)); C:=TArray The Create (3, 4, 5, 6); For I:=0 to 3 do writeln (b [I]); For I:=0 to 3 do writeln (c [I]); end; Any Delphi version can be methods a, b needs to support dynamic array (d4 +), c is needed to support generics (d2009 +), the latter two methods array subscript can only start from 0,,
CodePudding user response:
Var Const b: array [0.. 3] of integer=(1, 2, 3, 4); This is an array parameter form, the initialization data, can't again assignment,
Var b: array [4] 1.. of integer; This is to define an array variable, can be specified address subscript, read and write values, [0] : b=100; For I:=0 to 3 do B: [I]=100 + I;
CodePudding user response:
Your assignment method can only be defined when the assignment, if it is not the value of the law can only come one by one,,,
function a (); Var B: array [4] 1.. of integer; The begin [1] : b=2; [2] : b=4; [3] : b=3; [4] : b=7; end;