![]() |
|
|
#1
|
|||
|
|||
|
ок. хочу получить возможность работать со вложенными открытыми массивами, вроде такого:
[ 'a', ['b','c'], ['d',['e','f'],'g'], 'h' ] при этом желательно, чтобы это был массив array of const собственно вопросы возникли по статье: http://www.delphisources.ru/pages/fa..._of_const.html объявляю типы: Код:
type
ArrayOfConst = array of TVarRec;
TArrayOfConst = array [ 0 .. High (WORD) div SizeOf (TVarRec) - 1 ] of TVarRec;
PArrayOfConst = ^TArrayOfConst;
описываю функции слияния: Код:
function PArrayOfConstMerge (anArgs1, anArgs2: array of const) : PArrayOfConst;
var
I : WORD;
Index : WORD;
Length : WORD;
begin
Result := NIL;
try
Length := 0;
if ( High (anArgs1) >= 0 ) then
Length := Length + High (anArgs1) - Low (anArgs1) +1;
if ( High (anArgs2) >= 0 ) then
Length := Length + High (anArgs2) - Low (anArgs2) +1;
if ( Length > 0 ) then
begin
Result := AllocMem ( Length * SizeOf (TVarRec) );
Index := 0;
for I := Low (anArgs1) to High (anArgs1) do
begin
Result^ [Index] := anArgs1 [i];
Inc (Index);
end;
for I := Low (anArgs2) to High (anArgs2) do
begin
Result^ [Index] := anArgs2 [i];
Inc (Index);
end;
end;
except
Result := NIL;
end;
end;
function ArrayOfConstMerge (anArgs1, anArgs2: array of const) : ArrayOfConst;
var
I : WORD;
Index : WORD;
Length : WORD;
begin
Result := NIL;
try
Length := 0;
if ( High (anArgs1) >= 0 ) then
Length := Length + High (anArgs1) - Low (anArgs1) +1;
if ( High (anArgs2) >= 0 ) then
Length := Length + High (anArgs2) - Low (anArgs2) +1;
if ( Length > 0 ) then
begin
SetLength (Result,Length);
Index := 0;
for I := Low (anArgs1) to High (anArgs1) do
begin
Result [Index] := anArgs1 [i];
Inc (Index);
end;
for I := Low (anArgs2) to High (anArgs2) do
begin
Result [Index] := anArgs2 [i];
Inc (Index);
end;
end;
except
Result := NIL;
end;
end;передать окрытый массив в качестве параметра в другой открытый массив нельзя, поэтому передаем указатель на него: Код:
function ArrayOfConstToPointer (anArgs: array of const) : PArrayOfConst;
var
I : WORD;
Index : WORD;
Length : WORD;
begin
Result := NIL;
try
Length := 0;
if ( High (anArgs) >= 0 ) then
Length := Length + High (anArgs) - Low (anArgs) +1;
if ( Length > 0 ) then
begin
Result := AllocMem ( Length * SizeOf (TVarRec) );
Index := 0;
for I := Low (anArgs) to High (anArgs) do
begin
Result^ [Index] := anArgs [i];
Inc (Index);
end;
end;
except
Result := NIL;
end;
end;Последний раз редактировалось mirt steelwater, 16.11.2010 в 13:55. |