#1 2022-06-06 23:03

oem
Member
Registered: 2018-12-15
Posts: 9

Dynamic Multidimensional Arrays in Pascal

type
  MultiWideStringArray = array of array of WideString;

var
  EnglishSongNameArray: MultiWideStringArray;
begin

SetLength(EnglishSongNameArray, 5, 5);
  // Add your code here
  // Press Ctrl+Space for code completion
  // Hold Shift when loading a script to insert it inline
end.  

Doesnt seem to work

Offline

#2 2022-06-07 00:17

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,367

Re: Dynamic Multidimensional Arrays in Pascal

I think you will need to store a multidimensional array as a single dimensional array, with a simple remapping of cell coordinates.

The script below will set your new names to "Hello World", but using a two dimensional array to store the words.

type
  TTable = record
    Rows: Integer;
    Columns: Integer;
    Data: array of WideString;
  end;

function CreateTable(Rows, Columns: Integer): TTable;
begin
  Result.Rows := Rows;
  Result.Columns := Columns;
  SetLength(Result.Data, Rows * Columns);
end;

procedure SetTable(var Table: TTable; const Row, Column: Integer; const Value: WideString);
var
  Index: Integer;
begin
  Index := Row * Table.Rows + Column;
  Table.Data[Index] := Value;
end;

function GetTable(const Table: TTable; const Row, Column: Integer): WideString;
var
  Index: Integer;
begin
  Index := Row * Table.Rows + Column;
  Result := Table.Data[Index];
end;

var
  Table: TTable;

begin
  Table := CreateTable(2,3);
  SetTable(Table, 0, 0, 'Hello');
  SetTable(Table, 1, 2, 'World');
  FileName := GetTable(Table, 0, 0) + ' ' + GetTable(Table, 1, 2);
end.

Offline

Board footer

Powered by FluxBB