Implenentation

uses Gridlnput, Listlnput;

{$R *.DFM}

procedure TMainForm.ButtonListClick (Sender: TObject);
var
a: array of double; {Объявление динамческсго массива вещственных чисел}
i: integer; s, p: double;
begin
with ListForm do
if ShowModal=mrOk then
begin
SetLength(a, ListBoxArray.Items.Count); {Установка длиныы массива}
for i:=0 to ListBoxArray.Items.Count-1 do
a[i]:=StrToFloat(ListBoxArray.Items[i]); {Копирование значений в массив}
try
s:=0;
for i:=0 to Length(a)-1 do
s:=s+a[i]; {Суммирование всех чисел}
LabelSum1.Caption:=FloatToStr(s);
except
LabelSum1.Caption:= 'Ошибка вычисления суммы';
end;
try
p:=1;
for i:=0 to Length(a)-1 do
P:=P*a[i]; {Вычисление произведения всех чисел}
LabelProduct1.Caption:=FloatToStr(p);
except
LabelProduct1.Caption:='Ошибка вычисления произведения';
end;
end;
end;

procedure TMainForm.ButtonCloseClick(Sender: TObject);
begin // выход из программы
Close;
end;

procedure TMainForm.ButtonGridClick (Sender: TObject);
var
a: array of array of double; {Объявление двумерного динамического массива}
x,у: integer; s, p: double;
begin
with GridForm do
if ShowModal=mrOk then
begin
SetLength(a, GridArray.ColCount-2); {Установка длины массива по столбцам}
for x:=0 to Length(a)-1 do
SetLength (a[x], GridArray.RowCount-2); {Установка длины массива по рядам}
for x:=0 to Length (a)-1 do
for y:=0 to Length (a[x])-l do
a[x,y]:=StrToFloat(GridArray.Се11s[x+1,у+1]); {Копирование значений}
try
s:=0;
for x:=0 to Lengеh(a)-1 do
for y:=0 to length (a[x])-1 do
s:=s+a[x,y]; {Суммирование всех чисел}
LabelSum2.Caption:=FloatToStr(s);
except
LabelSum2.Capticn:='Ошибка вычисления суммы';
end;
try
p:=1;
for x:=0 to Length(a)-1 do
for y:=0 to Length(a[x])-1 do
p:=p*a[x,y];
LabelProduct2.Caption:=FloatToStr(p);
except
LabelProduct2.Caption:='Сшибка вычисления произведения';
end;
end;
end;

end.

Листинг 7. Текст вспомогательного модуля ListInput.pas.

unit ListInput;

Interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;

type
TListForm = class (TForm)
Label1: TLabel;
ListBoxArray: TListBox;
EditValue: TEdit;
Label2: TLabel;
ButtonAdd: TButton;
ButtonReplace: TButton;
ButtonOk: TButton;
ButtonCancel: TButton;
procedure ButronAddClick (Sender: TObject);
procedure LisiBoxArrayClick(Sender: TObject);
end;

Замечание

Обработчик ButtonAddClick coбытия нажатия кнопки ButtonAdd должен быть назначен для кнопки ButtonReplace с помощью инспектора объектов на странице Events.

var
ListForm: TListForm;


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: