1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, AxCtrls, OleCtrls, VCF1, OleCtnrs, TeEngine, Series,
ExtCtrls, TeeProcs, Chart, math,comobj;
type
TForm1 = class(TForm)
olcntnr1: TOleContainer;
Edit1: TEdit;
Label1: TLabel;
F1Book1: TF1Book;
Button1: TButton;
Label4: TLabel;
Edit4: TEdit;
F1Book2: TF1Book;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var x0,y0,z0,max,r:Real; i,j,n,nmax,k:Integer;
x,y,z,s: Array of real; XL,EXL: OleVariant;
begin
XL := CreateOleObject('Excel.Application');
XL.DisplayAlerts := false;
XL.WorkBooks.Add;
EXL := CreateOleObject('Excel.Application');
EXL.DisplayAlerts := false;
EXL.WorkBooks.Add;
// f1book1.Refresh;
// f1book2.refresh;
F1Book1.TextRC[1,1]:='x';
F1Book1.TextRC[1,2]:='y';
F1book1.TextRC[1,3]:='z';
F1Book1.TextRC[1,5]:='kol-vo tochek';
F1Book2.TextRC[1,1]:='x';
F1Book2.TextRC[1,2]:='y';
F1book2.TextRC[1,3]:='z';
n:=strtoint(Edit1.Text);
r:=strtofloat(edit4.text);
SetLength(x,n);
SetLength(y,n);
SetLength(z,n);
SetLength(s,n);
if r<=15 then begin
for i := 1 to n do
begin
x[i]:=Random(10)-5;
y[i]:=Random(10)-5;
z[i]:=Random(10)-5;
f1book1.numberrc[i+1,1]:=x[i];
f1book1.numberrc[i+1,2]:=y[i];
f1book1.numberrc[i+1,3]:=z[i];
XL.WorkBooks[1].WorkSheets[1].Cells[i,1] := x[i];
XL.WorkBooks[1].WorkSheets[1].Cells[i,2] := y[i];
XL.WorkBooks[1].WorkSheets[1].Cells[i,3] := z[i];
end;
XL.Visible := false;
XL.WorkBooks[1].SaveAs(ExtractFilePath(Application.ExeName)+'точки.xls');
xl.quit;
for i:=1 to n do
begin
s[i]:=0;
x0:=x[i]; y0:=y[i]; z0:=z[i];
for j:=1 to n do if j<>i then
begin
if sqrt(power(x[j]-x0, 2)+ Power(y[j]-y0, 2)+
Power (z[i]-z0, 2)) <= r then
s[i]:=s[i]+1;
end;
F1Book1.NumberRC[i+1,5]:=s[i];
end;
max:=s[1];
for i:=2 to n do
if s[i]>=max then begin
max:=s[i];
nmax:=i;
end;
F1Book2.NumberRC[2,1]:=x[nmax];
F1Book2.NumberRC[2,2]:=y[nmax];
F1Book2.NumberRC[2,3]:=z[nmax];
EXL.WorkBooks[1].WorkSheets[1].Cells[1,1]:=x[nmax];
EXL.WorkBooks[1].WorkSheets[1].Cells[1,2]:=y[nmax];
EXL.WorkBooks[1].WorkSheets[1].Cells[1,3]:=z[nmax];
k:=2;
for i:=1 to n do
if (s[i]=max) and (i<>nmax) then
begin
F1Book2.NumberRC[k+1,1]:=x[i];
F1Book2.NumberRC[k+1,2]:=y[i];
F1Book2.NumberRC[k+1,3]:=z[i];
EXL.WorkBooks[1].WorkSheets[1].Cells[k,1]:=x[i];
EXL.WorkBooks[1].WorkSheets[1].Cells[k,2]:=Y[i];
EXL.WorkBooks[1].WorkSheets[1].Cells[k,3]:=Z[i];
k:=k+1;
end;
EXL.Visible := false;
EXL.WorkBooks[1].SaveAs(ExtractFilePath(Application.ExeName)+'центр.xls');
exl.quit;
xl:=unassigned;
exl:=unassigned;
end else
label3.Caption:='введите R<=15!';
end;
end. |