![]() |
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; |
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.
|
Re: 3D Dynamic Array
Zitat:
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)
|
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. |
Re: 3D Dynamic Array
Zitat:
Delphi-Quellcode:
Grüße
for i:=0 to 9 do
for := 0 to 4 do multiarray[i,j,0]:='a'; Klaus |
Re: 3D Dynamic Array
what about the first and middle dimension :pale:
Edit: First Second Third dimension are the same ![]() 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'; |
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:
with the proposal of klaus1 you fill the complete array with 'a'
for i:=0 to 2; do //start to finish
multiarray[0,0,i]:='a'; because the 2 for functions access every element of your array. |
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? |
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 |
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 15:58 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz