AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

3D Dynamic Array

Ein Thema von nanix · begonnen am 11. Jan 2010 · letzter Beitrag vom 11. Jan 2010
Antwort Antwort
Seite 1 von 2  1 2      
nanix
(Gast)

n/a Beiträge
 
#1

3D Dynamic Array

  Alt 11. Jan 2010, 00:21
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;
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#2

Re: 3D Dynamic Array

  Alt 11. Jan 2010, 02:56
What do you mean by "sets last dimension"? You're never "setting a dimension" when accessing with indexes, you simply write to one element.
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
tkone

Registriert seit: 2. Okt 2009
Ort: Sachsen
63 Beiträge
 
Delphi 7 Professional
 
#3

Re: 3D Dynamic Array

  Alt 11. Jan 2010, 09:30
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)
  Mit Zitat antworten Zitat
nanix
(Gast)

n/a Beiträge
 
#4

Re: 3D Dynamic Array

  Alt 11. Jan 2010, 10:06
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.
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.768 Beiträge
 
Delphi 10.4 Sydney
 
#5

Re: 3D Dynamic Array

  Alt 11. Jan 2010, 10:18
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
Klaus
  Mit Zitat antworten Zitat
nanix
(Gast)

n/a Beiträge
 
#6

Re: 3D Dynamic Array

  Alt 11. Jan 2010, 10:27
what about the first and middle dimension

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';
  Mit Zitat antworten Zitat
tkone

Registriert seit: 2. Okt 2009
Ort: Sachsen
63 Beiträge
 
Delphi 7 Professional
 
#7

Re: 3D Dynamic Array

  Alt 11. Jan 2010, 10:46
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.
Angehängte Grafiken
Dateityp: bmp unbenannt_106.bmp (79,8 KB, 8x aufgerufen)
  Mit Zitat antworten Zitat
nanix
(Gast)

n/a Beiträge
 
#8

Re: 3D Dynamic Array

  Alt 11. Jan 2010, 11:03
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?
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.768 Beiträge
 
Delphi 10.4 Sydney
 
#9

Re: 3D Dynamic Array

  Alt 11. Jan 2010, 11:23
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
Miniaturansicht angehängter Grafiken
3dimensions_160.jpg  
Klaus
  Mit Zitat antworten Zitat
Medium

Registriert seit: 23. Jan 2008
3.686 Beiträge
 
Delphi 2007 Enterprise
 
#10

Re: 3D Dynamic Array

  Alt 11. Jan 2010, 11:30
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.)
"When one person suffers from a delusion, it is called insanity. When a million people suffer from a delusion, it is called religion." (Richard Dawkins)
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 2  1 2      


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:34 Uhr.
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