📄 testdelphinetdynamicarray.out
字号:
unit TestDelphiNetDynamicArray;
{ This unit compiles but is not semantically meaningfull
it is test cases for the code formatting utility
Tests of the Delphi.net 'new' keyword for array creation
from TridenT
}
interface
implementation
uses
SysUtils;
type
TObjectDynArray = array of TObject;
procedure TabObjet(Args: array of TObject);
var
i: integer;
begin
Writeln('Dans la proc閐ure TabObjet');
for i := Low(Args) to High(Args) do
WriteLn('L''閘閙ent ', I, ' est du type ', Args[i].GetType.FullName,
' sa valeur est ''', Args[i], '''');
ReadLn;
end;
procedure TabConst(A: array of const);
var
i: integer;
begin
Writeln('Dans la proc閐ure TabConst');
for i := Low(A) to High(A) do
// WriteLn('Index ', I, ': ', A[i].GetType.FullName);
WriteLn('L''閘閙ent ', I, ' est du type ', A[i].GetType.FullName,
' sa valeur est ''', A[i], '''');
ReadLn;
end;
procedure Test02;
var
X, Y: array[, ] of integer; // 2 dimensional array
i, j: integer;
begin
i := 2;
j := 3;
X := New(array[i, j] of integer); // only size of 2x3 matrix
X[0, 0] := 1;
X[0, 1] := 2;
X[0, 2] := 3;
X[1, 0] := 4;
X[1, 1] := 5;
X[1, 2] := 6;
// type and initializer list
Y := New(array[, ] of integer, ((1, 2, 3), (4, 5, 6)));
for i := 0 to 1 do
for j := 0 to 2 do
if X[i, j] <> Y[i, j] then
writeln(i, j);
writeln('done');
readln;
end;
// D閏lare et initialise qq variables
var
S1: string = 'Une cha頽e';
I: integer = 90;
D1: double = 5.6;
D2: double = 3.14159;
Etat: boolean = True;
S2: string = 's';
TbObj: array of TObject;
begin
// Passage d'un nombre de param鑤re variable sans pr閏iser le type, uniquement des constantes
TabConst(['Une cha頽e', 90, 5.6, 3.14159, True, 's']);
// Passage d'un nombre param鑤re variable sans pr閏iser le type, mixte constantes et variables
TabConst([S1, I, 5.6, D2, Etat, 's']);
// Dans le second appel le type du 2 閙e param鑤re est diff閞ent
// A la compilation 90 est vu comme un type Byte et I est de type Integer
// Cr閍tion dynamique d'un tableau
TbObj := New(TObjectDynArray, 6);
// La directive AutoBox permet d'関iter le transtypage explicite n閏essaire pour chaque 閘閙ent du tableau
// Cette directive effectue implicitement le cast
{$AutoBox on}
// Renseigne le tableau avec des variables
TbObj := New(array[] of TObject, (S1, I, D1, D2, Etat, S2));
{$AutoBox off}
TabObjet(TbObj);
{$AutoBox on}
// Renseigne le tableau avec des variables et des constantes
TbObj := New(array[] of TObject, (S1, I, 5.6, D2, Etat, 's'));
{$AutoBox off}
TabObjet(TbObj);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -