Answer the question
In order to leave comments, you need to log in
How are multidimensional arrays filled?
I am rewriting a program from delphi to c#, I have no experience with delphi. I ran into a problem, I don’t understand how the mkts and msh array is filled . I would appreciate any help.
mkts = array [0..3, 1..6, 1..16] of SmallInt;
msh = array[1..392] of SmallInt;
TPmkts = ^mkts;
TPmsh = ^msh;
Pkts: array[1..Blocks, 1..RTParts] of TPmkts = ( (nil, nil),
(nil, nil), (nil, nil), (nil, nil) );
Psh: array[1..4, 1..2] of TPmsh = ( (nil, nil),
(nil, nil), (nil, nil), (nil, nil) );
...
Df: array[1..4, 1..2] of integer;
{------------------------------------------------------------------------}
function OpenA(FileName: ShortString; Mode: LongWord): integer;
begin
Result:= FileOpen(FileName, Mode);
end;
{------------------------------------------------------------------------}
function ReadA(Df: integer; Pmas: Pointer; L: word): boolean;
begin
Result:= false;
if FileSeek(Df, 0, 0) = 0 then
if FileRead(Df, Pmas^, L) > 0 then
Result:= true;
end;
...
{------------------------------------------------------------------------}
Df[BlNum, ROTO]:= OpenA(ShifrFileName, fmShareDenyNone);
{ Выделение памяти }
New(Psh[4, 1]);
if not ReadA(Df[4, 1], Psh[4, 1], 784) then
begin
CloseA(Df[4, 1]);
Dispose(Psh[4, 1]);
Exit;
end;
Pkts[4, 1]:= @Psh[4, 1]^[9];
Answer the question
In order to leave comments, you need to log in
New(Psh[4, 1]);
We translate into C#. True, there is one catch. Arrays in c# start only from 0, and you need to look: either start a blank 0th element, or adjust the indices. So we have two options.
Psh[4][1] = new short[393];
Psh[3][0] = new short[392];
(for example, I work with the second)function OpenA(FileName: ShortString; Mode: LongWord): integer;
Stream OpenA(string FileName, FileAccess access);
if (!ReadA(Df[3][0], Psh[3][0], 392) {
CloseA(Df[3, 0]);
Psh[3][0] = null;
return;
}
Pkts[3][0].array = Psh[3][0];
Pkts[3][0].offset = 8;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question