December 2009
M T W T F S S
« Oct   Jan »
 123456
78910111213
14151617181920
21222324252627
28293031  

Statistik Pengguna

joomla counter
Sejak Januari 2010

3D matrik on Delphi

unit WinForm;

interface

uses
  System.Drawing, System.Collections, System.ComponentModel,
  System.Windows.Forms, System.Data, Borland.Vcl.SysUtils;

type
  TWinForm = class(System.Windows.Forms.Form)
  {$REGION 'Designer Managed Code'}
  strict private
    ///
    /// Required designer variable.
    ///
    Components: System.ComponentModel.Container;
    Button1: System.Windows.Forms.Button;
    Button2: System.Windows.Forms.Button;
    TextBox1: System.Windows.Forms.TextBox;
    RichTextBox1: System.Windows.Forms.RichTextBox;
    Label1: System.Windows.Forms.Label;
    Label2: System.Windows.Forms.Label;
    Label3: System.Windows.Forms.Label;
    TextBox2: System.Windows.Forms.TextBox;
    TextBox3: System.Windows.Forms.TextBox;
    TextBox4: System.Windows.Forms.TextBox;
    Button3: System.Windows.Forms.Button;
    ///
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///
    procedure InitializeComponent;
    procedure Button1_Click(sender: System.Object; e: System.EventArgs);
    procedure Button2_Click(sender: System.Object; e: System.EventArgs);
    procedure TextBox1_TextChanged(sender: System.Object; e: System.EventArgs);
    procedure Button3_Click(sender: System.Object; e: System.EventArgs);
  {$ENDREGION}
  strict protected
    ///
    /// Clean up any resources being used.
    ///
    procedure Dispose(Disposing: Boolean); override;
  private
    { Private Declarations }
    mat3D : array of array of array of integer;
    dimX, dimY, dimZ : integer;
  public
    constructor Create;
  end;

  [assembly: RuntimeRequiredAttribute(TypeOf(TWinForm))]

implementation

{$REGION 'Windows Form Designer generated code'}
///
/// Required method for Designer support -- do not modify
/// the contents of this method with the code editor.
///
procedure TWinForm.InitializeComponent;
begin
  Self.Button1 := System.Windows.Forms.Button.Create;
  Self.Button2 := System.Windows.Forms.Button.Create;
  Self.TextBox1 := System.Windows.Forms.TextBox.Create;
  Self.RichTextBox1 := System.Windows.Forms.RichTextBox.Create;
  Self.Label1 := System.Windows.Forms.Label.Create;
  Self.Label2 := System.Windows.Forms.Label.Create;
  Self.Label3 := System.Windows.Forms.Label.Create;
  Self.TextBox2 := System.Windows.Forms.TextBox.Create;
  Self.TextBox3 := System.Windows.Forms.TextBox.Create;
  Self.TextBox4 := System.Windows.Forms.TextBox.Create;
  Self.Button3 := System.Windows.Forms.Button.Create;
  Self.SuspendLayout;
  //
  // Button1
  //
  Self.Button1.Location := System.Drawing.Point.Create(16, 24);
  Self.Button1.Name := 'Button1';
  Self.Button1.Size := System.Drawing.Size.Create(80, 40);
  Self.Button1.TabIndex := 0;
  Self.Button1.Text := 'Inisialisasi';
  Include(Self.Button1.Click, Self.Button1_Click);
  //
  // Button2
  //
  Self.Button2.Location := System.Drawing.Point.Create(104, 24);
  Self.Button2.Name := 'Button2';
  Self.Button2.Size := System.Drawing.Size.Create(80, 40);
  Self.Button2.TabIndex := 2;
  Self.Button2.Text := 'Show';
  Include(Self.Button2.Click, Self.Button2_Click);
  //
  // TextBox1
  //
  Self.TextBox1.Location := System.Drawing.Point.Create(16, 72);
  Self.TextBox1.Name := 'TextBox1';
  Self.TextBox1.Size := System.Drawing.Size.Create(96, 20);
  Self.TextBox1.TabIndex := 3;
  Self.TextBox1.Text := '1';
  Include(Self.TextBox1.TextChanged, Self.TextBox1_TextChanged);
  //
  // RichTextBox1
  //
  Self.RichTextBox1.Location := System.Drawing.Point.Create(376, 8);
  Self.RichTextBox1.Name := 'RichTextBox1';
  Self.RichTextBox1.Size := System.Drawing.Size.Create(200, 296);
  Self.RichTextBox1.TabIndex := 4;
  Self.RichTextBox1.Text := 'RichTextBox1';
  //
  // Label1
  //
  Self.Label1.Location := System.Drawing.Point.Create(16, 104);
  Self.Label1.Name := 'Label1';
  Self.Label1.TabIndex := 5;
  Self.Label1.Text := 'x';
  //
  // Label2
  //
  Self.Label2.Location := System.Drawing.Point.Create(16, 136);
  Self.Label2.Name := 'Label2';
  Self.Label2.TabIndex := 6;
  Self.Label2.Text := 'y';
  //
  // Label3
  //
  Self.Label3.Location := System.Drawing.Point.Create(16, 168);
  Self.Label3.Name := 'Label3';
  Self.Label3.TabIndex := 7;
  Self.Label3.Text := 'z';
  //
  // TextBox2
  //
  Self.TextBox2.Location := System.Drawing.Point.Create(80, 96);
  Self.TextBox2.Name := 'TextBox2';
  Self.TextBox2.TabIndex := 8;
  Self.TextBox2.Text := '1';
  //
  // TextBox3
  //
  Self.TextBox3.Location := System.Drawing.Point.Create(80, 128);
  Self.TextBox3.Name := 'TextBox3';
  Self.TextBox3.TabIndex := 9;
  Self.TextBox3.Text := '1';
  //
  // TextBox4
  //
  Self.TextBox4.Location := System.Drawing.Point.Create(80, 160);
  Self.TextBox4.Name := 'TextBox4';
  Self.TextBox4.TabIndex := 10;
  Self.TextBox4.Text := '1';
  //
  // Button3
  //
  Self.Button3.Location := System.Drawing.Point.Create(80, 192);
  Self.Button3.Name := 'Button3';
  Self.Button3.Size := System.Drawing.Size.Create(104, 40);
  Self.Button3.TabIndex := 11;
  Self.Button3.Text := 'Insert';
  Include(Self.Button3.Click, Self.Button3_Click);
  //
  // TWinForm
  //
  Self.AutoScaleBaseSize := System.Drawing.Size.Create(5, 13);
  Self.ClientSize := System.Drawing.Size.Create(584, 318);
  Self.Controls.Add(Self.Button3);
  Self.Controls.Add(Self.TextBox4);
  Self.Controls.Add(Self.TextBox3);
  Self.Controls.Add(Self.TextBox2);
  Self.Controls.Add(Self.Label3);
  Self.Controls.Add(Self.Label2);
  Self.Controls.Add(Self.Label1);
  Self.Controls.Add(Self.RichTextBox1);
  Self.Controls.Add(Self.TextBox1);
  Self.Controls.Add(Self.Button2);
  Self.Controls.Add(Self.Button1);
  Self.Name := 'TWinForm';
  Self.Text := 'WinForm';
  Self.ResumeLayout(False);
end;
{$ENDREGION}

procedure TWinForm.Dispose(Disposing: Boolean);
begin
  if Disposing then
  begin
    if Components <> nil then
      Components.Dispose();
  end;
  inherited Dispose(Disposing);
end;

constructor TWinForm.Create;
begin
  inherited Create;
  //
  // Required for Windows Form Designer support
  //
  InitializeComponent;
  //
  // TODO: Add any constructor code after InitializeComponent call
  //
end;

procedure TWinForm.Button3_Click(sender: System.Object; e: System.EventArgs);
var pj, lb, tg : integer;
i, j, k : integer;
begin
  pj := 2;
  lb := 2;
  tg := 3;
  for i:= StrToInt(TextBox2.Text) to StrToInt(TextBox2.Text) + pj do
  begin
    for j:= StrToInt(TextBox3.Text) to StrToInt(TextBox3.Text) + lb do
    begin
      for k:= StrToInt(TextBox4.Text) to StrToInt(TextBox4.Text) + tg do
      begin
          //mat3D[i-1][j-1][k-1] := k;
          mat3D[i-1][j-1][k-1] := mat3D[i-1][j-1][k-1] + 1;
      end;
    end;
  end;
  Button2_Click(sender, e);
end;

procedure TWinForm.TextBox1_TextChanged(sender: System.Object; e: System.EventArgs);
begin
  Button2_Click(sender, e);
end;

procedure TWinForm.Button2_Click(sender: System.Object; e: System.EventArgs);
var i, j : integer;
begin
  RichTextBox1.Text := '';
  for i := 1 to dimX do
  begin
    for j:= 1 to dimY do
    begin
      RichTextBox1.Text := RichTextBox1.Text + '  ' + intToStr(mat3D[i-1][j-1][StrToInt(TextBox1.Text)-1]);
    end;
    RichTextBox1.Text := RichTextBox1.Text + #13;
  end;
end;

procedure TWinForm.Button1_Click(sender: System.Object; e: System.EventArgs);
var i,j,k :integer;

begin
  dimX := 10;
  dimY := 5;
  dimZ := 10;
  SetLength(mat3D, dimX);
  for i:= 1 to dimX do
  begin
    SetLength(mat3D[i-1], dimY);
  end;
  for i:= 1 to dimX do
  begin
    for j:= 1 to dimY do
    begin
        SetLength(mat3D[i-1][j-1], dimZ);
    end;
  end;

  for i:= 1 to dimX do
  begin
    for j:= 1 to dimY do
    begin
      for k:= 1 to dimZ do
      begin
          //mat3D[i-1][j-1][k-1] := k;
          mat3D[i-1][j-1][k-1] := 0;
      end;
    end;
  end;
end;

end.

4 comments to 3D matrik on Delphi

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <span class=""> <p> <br>

Spam Protection by WP-SpamFree