1 |
(* ***** BEGIN LICENSE BLOCK *****
|
2 |
* Version: MPL 1.1
|
3 |
*
|
4 |
* The contents of this file are subject to the Mozilla Public License Version
|
5 |
* 1.1 (the "License"); you may not use this file except in compliance with
|
6 |
* the License. You may obtain a copy of the License at
|
7 |
* http://www.mozilla.org/MPL/
|
8 |
*
|
9 |
* Software distributed under the License is distributed on an "AS IS" basis,
|
10 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
11 |
* for the specific language governing rights and limitations under the
|
12 |
* License.
|
13 |
*
|
14 |
* The Original Code is TurboPower SysTools
|
15 |
*
|
16 |
* The Initial Developer of the Original Code is
|
17 |
* TurboPower Software
|
18 |
*
|
19 |
* Portions created by the Initial Developer are Copyright (C) 1996-2002
|
20 |
* the Initial Developer. All Rights Reserved.
|
21 |
*
|
22 |
* Contributor(s):
|
23 |
*
|
24 |
* ***** END LICENSE BLOCK ***** *)
|
25 |
|
26 |
unit Ex3DArrU;
|
27 |
|
28 |
interface
|
29 |
|
30 |
uses
|
31 |
Windows, Messages, SysUtils, Classes, Graphics, Controls,
|
32 |
Forms, Dialogs, StdCtrls,
|
33 |
|
34 |
StConst, StBase, StLArr;
|
35 |
|
36 |
type
|
37 |
TMy3D = class(TStLArray)
|
38 |
protected
|
39 |
XMax,
|
40 |
YMax,
|
41 |
ZMax : LongInt;
|
42 |
public
|
43 |
constructor Create(X, Y, Z : Cardinal);
|
44 |
destructor Destroy; override;
|
45 |
end;
|
46 |
|
47 |
TForm1 = class(TForm)
|
48 |
Button1: TButton;
|
49 |
Edit4: TEdit;
|
50 |
Label4: TLabel;
|
51 |
GroupBox1: TGroupBox;
|
52 |
Label1: TLabel;
|
53 |
Edit1: TEdit;
|
54 |
Label2: TLabel;
|
55 |
Edit2: TEdit;
|
56 |
Label3: TLabel;
|
57 |
Edit3: TEdit;
|
58 |
procedure FormCreate(Sender: TObject);
|
59 |
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
60 |
procedure Button1Click(Sender: TObject);
|
61 |
private
|
62 |
{ Private declarations }
|
63 |
public
|
64 |
{ Public declarations }
|
65 |
My3D : TMy3D;
|
66 |
end;
|
67 |
|
68 |
var
|
69 |
Form1: TForm1;
|
70 |
|
71 |
implementation
|
72 |
|
73 |
{$R *.DFM}
|
74 |
const
|
75 |
MaxX = 50;
|
76 |
MaxY = 50;
|
77 |
MaxZ = 50;
|
78 |
|
79 |
constructor TMy3D.Create(X, Y, Z : Cardinal);
|
80 |
var
|
81 |
row,
|
82 |
col,
|
83 |
up,
|
84 |
Value : LongInt;
|
85 |
A : TStLMatrix;
|
86 |
begin
|
87 |
XMax := X;
|
88 |
YMax := Y;
|
89 |
ZMax := Z;
|
90 |
|
91 |
inherited Create(ZMax, SizeOf(TStLMatrix));
|
92 |
for up := 0 to ZMax-1 do
|
93 |
begin
|
94 |
A := TStLMatrix.Create(XMax, YMax, SizeOf(LongInt));
|
95 |
for row := 0 to YMax-1 do
|
96 |
for col := 0 to XMax-1 do begin
|
97 |
Value := up+100*col+10000*row;
|
98 |
A.Put(row, col, Value);
|
99 |
end;
|
100 |
Put(up, A);
|
101 |
end;
|
102 |
end;
|
103 |
|
104 |
destructor TMy3D.Destroy;
|
105 |
var
|
106 |
Up : LongInt;
|
107 |
A : TStLMatrix;
|
108 |
begin
|
109 |
for Up := 0 to ZMax-1 do
|
110 |
begin
|
111 |
Get(Up, A);
|
112 |
if Assigned(A) then
|
113 |
A.Free;
|
114 |
end;
|
115 |
inherited Destroy;
|
116 |
end;
|
117 |
|
118 |
procedure TForm1.FormCreate(Sender: TObject);
|
119 |
begin
|
120 |
My3D := TMy3D.Create(MaxX, MaxY, MaxZ);
|
121 |
end;
|
122 |
|
123 |
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
|
124 |
begin
|
125 |
My3D.Free;
|
126 |
end;
|
127 |
|
128 |
procedure TForm1.Button1Click(Sender: TObject);
|
129 |
var
|
130 |
XV,
|
131 |
YV,
|
132 |
ZV,
|
133 |
Value : LongInt;
|
134 |
Z : TStLMatrix;
|
135 |
begin
|
136 |
XV := StrToInt(Edit1.Text);
|
137 |
YV := StrToInt(Edit2.Text);
|
138 |
ZV := StrToInt(Edit3.Text);
|
139 |
if (XV < 0) or (XV >= MaxX) then begin
|
140 |
Edit1.Text := '0';
|
141 |
XV := StrToInt(Edit1.Text);
|
142 |
end;
|
143 |
if (YV < 0) or (YV >= MaxY) then begin
|
144 |
Edit2.Text := '0';
|
145 |
YV := StrToInt(Edit2.Text);
|
146 |
end;
|
147 |
if (ZV < 0) or (ZV >= MaxZ) then begin
|
148 |
Edit3.Text := '0';
|
149 |
ZV := StrToInt(Edit3.Text);
|
150 |
end;
|
151 |
|
152 |
My3D.Get(ZV, Z);
|
153 |
Z.Get(XV, YV, Value);
|
154 |
Edit4.Text := IntToStr(Value);
|
155 |
end;
|
156 |
|
157 |
end.
|