Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Delphi 3D Dynamic Array (https://www.delphipraxis.net/145920-3d-dynamic-array.html)

nanix 10. Jan 2010 23:21


3D Dynamic Array
 
Hello,

ok i have a problem with 3d dimensional dynamic array.How could i set each dimension seperatly.String value

Delphi-Quellcode:
Something 0
     Another 0
           That 0
     Another 1
           That 0
Delphi-Quellcode:
procedure TForm5.Button1Click(Sender: TObject);
var
i,j,l:integer;
 multiArray : Array of Array of array of string;
begin
  // Set the length of the 1st dimension of the multi-dim array
  SetLength(multiArray,10);

  // Set the length of the 3 sub-arrays
  SetLength(multiArray[0],5);
  SetLength(multiArray[1],5);
  SetLength(multiArray[2],5);

  SetLength(multiArray[0][0],1);
  SetLength(multiArray[1][1],1);
  SetLength(multiArray[2][2],1);


  // Set elements of this array
  multiarray[0,0,0]:='a'; //<< only sets last dimension
end;

Medium 11. Jan 2010 01:56

Re: 3D Dynamic Array
 
What do you mean by "sets last dimension"? You're never "setting a dimension" when accessing with indexes, you simply write to one element.

tkone 11. Jan 2010 08:30

Re: 3D Dynamic Array
 
Zitat:

Zitat von nanix
Delphi-Quellcode:
procedure TForm5.Button1Click(Sender: TObject);
var
i,j,l:integer;
 multiArray : Array of Array of array of string;
begin
  SetLength(multiArray,10);
  SetLength(multiArray[0],5);
  SetLength(multiArray[1],5);
  SetLength(multiArray[2],5);
  SetLength(multiArray[0][0],1);
  SetLength(multiArray[1][1],1);
  SetLength(multiArray[2][2],1);

If you want every Subarray(like you call the 2nd and 3rd dimension) to have other lengths, then you can do it the way you wrote.
But if every Subarray has he same length in one dimension(like in your example) then you can set his length much easier.

Code:
Setlength(multiarray,10,5,1)

nanix 11. Jan 2010 09:06

Re: 3D Dynamic Array
 
yea but how do i set value for each dimension in 3d array


like i do now multiarray[0,0,0]:='a';

but for each dimension seperatly becouse if i do know it only sets last dimension thus third the values.

Klaus01 11. Jan 2010 09:18

Re: 3D Dynamic Array
 
Zitat:

Zitat von nanix
yea but how do i set value for each dimension in 3d array


like i do now multiarray[0,0,0]:='a';

but for each dimension seperatly becouse if i do know it only sets last dimension thus third the values.

Delphi-Quellcode:
for i:=0 to 9 do
  for := 0 to 4 do
    multiarray[i,j,0]:='a';
Grüße
Klaus

nanix 11. Jan 2010 09:27

Re: 3D Dynamic Array
 
what about the first and middle dimension :pale:

Edit: First Second Third dimension are the same


http://img.techpowerup.org/100111/Capture049.jpg


this code is the same dosent do what i need
Delphi-Quellcode:
for i:=0 to 9 do
  for j:= 0 to 4 do
    multiarray[i,0,0]:='a';

tkone 11. Jan 2010 09:46

Re: 3D Dynamic Array
 
Liste der Anhänge anzeigen (Anzahl: 1)
the values are set by accessing the correct field and associate a value to it.
like you wrote already.

in my eyample you got a cubic field with 3x3x3 elements.

with multiarray[0,0,0] you access the first element (upper left field)
with multiarray[2,2,2] you access the last element (lower right field)
a.s.o.

if you want to insert strings into a whole dimension(for example fill the complete 3rd dimension with 'a')
just put it into a repeating-prozess.
Delphi-Quellcode:
for i:=0 to 2; do //start to finish
multiarray[0,0,i]:='a';
with the proposal of klaus1 you fill the complete array with 'a'
because the 2 for functions access every element of your array.

nanix 11. Jan 2010 10:03

Re: 3D Dynamic Array
 
Yea look at this

Delphi-Quellcode:
unit Unit6;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;
 const
   Days : array[0..6] of string =
   (
     'Win32_Processor',
     'Win32_OperatingSystem',
     'Win32_SystemSetting',
     'Win32_PerfRawData_PerfOS_Memory',
     'Win32_PerfRawData_PerfOS_Processor',
     'Win32_PerfRawData_PerfOS_System',
     'Win32_PerfRawData_PerfProc_Process'
   ) ;
type
  TForm6 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form6: TForm6;
  multiarray:array of array of array of string;
implementation

{$R *.dfm}

procedure TForm6.FormCreate(Sender: TObject);
var
i,j:integer;
begin
Setlength(multiarray,length(days),1,1);

  for j:=0 to 6 do //start to finish

multiarray[j,0,0]:=days[j];
end;

end.

I want to have first dimention const array days which i successfully loaded.
But how do i set first middle and last seperatly.

I want to have diffrent array contents per dimension.

Whats so hard to understand here?

Klaus01 11. Jan 2010 10:23

Re: 3D Dynamic Array
 
Liste der Anhänge anzeigen (Anzahl: 1)
Hi,

if you want to set values only the 3. dimension (k; 0 to x)
you have to set the index for dimension 1 and 2 constant.

if you want to set values only the 2. dimension (j; 0 to x)
you have to set the index for dimension 1 and 3 as constant.

Please see picture.

Regards
Klaus

Medium 11. Jan 2010 10:30

Re: 3D Dynamic Array
 
I have the feeling that it's time to ask, what you ultimately want to achieve. What in detail do you want to express within the array? (I have the slight hunch that you might not really need a 3D array, but can't really tell because I've no clue where you want to go with this.)


Alle Zeitangaben in WEZ +1. Es ist jetzt 23:39 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz