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;

CodePudding user response:

refer to the second floor DelphiGuy response:
three 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,


Excuse me, use the second method, if b is a two-dimensional array what to write?
Var
B: an array of an array of integer;
I, j: integer;
The begin
B:=VarArrayOf ([2, 3, 4, 5], [3,7,4,0]);
For I:=0 to 3 do writeln (b [I]);
For j:=0 to 1 do writeln (b [j]);
end;
This is correct? Thank you very much ~ ~ ~

CodePudding user response:

B:=VarArrayOf ([[2, 3, 4, 5], [3,7,4,0]]).
If it is a high version, xe7 +, can direct: b:=[[2, 3, 4, 5], [3,7,4,0]].

CodePudding user response:

refer to 6th floor DelphiGuy response:
b:=VarArrayOf ([[2, 3, 4, 5], [3,7,4,0]]).
If it is a high version, xe7 +, can direct: b:=[[2, 3, 4, 5], [3,7,4,0]].


I'm sorry, this is no good, Delphi inside the pit is too much, to:
SetLength (y, 2, 4);
[0] : y=VarArrayOf ([2, 3, 4, 5));
[1] : Y=VarArrayOf (,7,4,0 [3]);
XE7 +, b:=[[2, 3, 4, 5], [3,7,4,0]]. Yes,
  • Related