Тема: Проста програма на Delphi для визначення прощі чоторикутника
Підкажіть, де тут помилка?
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Label3: TLabel;
Edit2: TEdit;
Label4: TLabel;
Edit3: TEdit;
Label5: TLabel;
Edit4: TEdit;
Button1: TButton;
Label6: TLabel;
Edit5: TEdit;
Label7: TLabel;
Edit6: TEdit;
Label8: TLabel;
Edit7: TEdit;
Label9: TLabel;
Edit8: TEdit;
Label10: TLabel;
Edit9: TEdit;
Button2: TButton;
Label11: TLabel;
Edit10: TEdit;
procedure Button1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit3KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Edit4KeyPress(Sender: TObject; var Key: Char);
procedure Edit5KeyPress(Sender: TObject; var Key: Char);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1; a,b,c,d,s,s1,s2,p1,p2,a1,a2,b1,b2,c1,c2,d2,d1,dg,dg1:Real;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
if ((Edit1.text='') or (Edit2.Text='')or (Edit3.Text='') or (Edit4.Text='')
or(Edit5.text='') or (Edit6.text='') or (Edit7.text='') or (Edit8.text='')
or (Edit9.Text='')) then begin
showMessage('Ââåä³òü äàí³');
Edit1.SetFocus;
exit;
end;
a1:=StrToFloat(Edit1.Text);
a2:=StrToFloat(Edit2.Text);
b1:=StrToFloat(Edit3.Text);
b2:=StrToFloat(Edit4.Text);
c1:=StrToFloat(Edit5.Text);
c2:=StrToFloat(Edit6.Text);
d1:=StrToFloat(Edit7.Text);
d2:=StrToFloat(Edit8.Text);
dg:=StrToFloat(Edit9.Text);
a:=Sqrt(sqr(b1-a1)+sqr(b2-a2));
b:=Sqrt(sqr(c1-b1)+sqr(c2-b2));
c:=Sqrt(sqr(d1-c1)+sqr(d2-c2));
d:=Sqrt(sqr(a1-d1)+sqr(a2-d2));
p1:=(a+b+dg)/2;
s1:=Sqrt(p1*(p1-a)*(p1-b)*(p1-dg));
p2:=(c+d+dg)/2;
s2:=Sqrt(p2*(p2-c)*(p2-d)*(p2-dg));
s:=s1+s2;
ShowMessage('Ïëîùà ÷îòèðèêóòíèêà= '+FloatToStr(s));
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
#8,'0'..'9' : ; // öèôðû è <Back Space>
'.',',':
begin
if Key <> DecimalSeparator then
Key := DecimalSeparator;
if Pos(DecimalSeparator,Edit1.Text) <> 0
then begin Key := Chr(0);
ShowMessage('Âæå ââåäåííî êîìó');
end;
end;
'-':
if Length(Edit1.Text) <> 0
then Key := Chr(0);
else
key := Chr(0);
end;
end;
procedure TForm1.Edit3KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
#8,'0'..'9' : ; // öèôðû è <Back Space>
'.',',':
begin
if Key <> DecimalSeparator then
Key := DecimalSeparator;
if Pos(DecimalSeparator,Edit3.Text) <> 0
then begin Key := Chr(0);
ShowMessage('Âæå ââåäåííî êîìó');
end;
end;
'-':
if Length(Edit3.Text) <> 0
then Key := Chr(0);
else
key := Chr(0);
end;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
#8,'0'..'9' : ; // öèôðû è <Back Space>
'.',',':
begin
if Key <> DecimalSeparator then
Key := DecimalSeparator;
if Pos(DecimalSeparator,Edit2.Text) <> 0
then begin Key := Chr(0);
ShowMessage('Âæå ââåäåííî êîìó');
end;
end;
'-':
if Length(Edit2.Text) <> 0
then Key := Chr(0);
else
key := Chr(0);
end;
end;
procedure TForm1.Edit4KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
#8,'0'..'9' : ; // öèôðû è <Back Space>
'.',',':
begin
if Key <> DecimalSeparator then
Key := DecimalSeparator;
if Pos(DecimalSeparator,Edit4.Text) <> 0
then begin Key := Chr(0);
ShowMessage('Âæå ââåäåííî êîìó');
end;
end;
'-':
if Length(Edit4.Text) <> 0
then Key := Chr(0);
else
key := Chr(0);
end;
end;
procedure TForm1.Edit5KeyPress(Sender: TObject; var Key: Char);
begin
case Key of
#8,'0'..'9' : ; // öèôðû è <Back Space>
'.',',':
begin
if Key <> DecimalSeparator then
Key := DecimalSeparator;
if Pos(DecimalSeparator,Edit5.Text) <> 0
then begin Key := Chr(0);
ShowMessage('Âæå ââåäåííî êîìó');
end;
end;
'-':
if Length(Edit5.Text) <> 0
then Key := Chr(0);
else
key := Chr(0);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if ((Edit1.text='') or (Edit2.Text='')or (Edit3.Text='') or (Edit4.Text='')
or(Edit5.text='') or (Edit6.text='') or (Edit7.text='') or (Edit8.text='')) then begin
showMessage('Ââåä³òü äàí³');
Edit1.SetFocus;
exit;
end;
a1:=StrToFloat(Edit1.Text);
a2:=StrToFloat(Edit2.Text);
b1:=StrToFloat(Edit3.Text);
b2:=StrToFloat(Edit4.Text);
c1:=StrToFloat(Edit5.Text);
c2:=StrToFloat(Edit6.Text);
d1:=StrToFloat(Edit7.Text);
d2:=StrToFloat(Edit8.Text);
dg:=StrToFloat(Edit9.Text);
a:=Sqrt(sqr(b1-a1)+sqr(b2-a2));
b:=Sqrt(sqr(c1-b1)+sqr(c2-b2));
c:=Sqrt(sqr(d1-c1)+sqr(d2-c2));
d:=Sqrt(sqr(a1-d1)+sqr(a2-d2));
dg1:=Sqrt(sqr(c1-a1)+sqr(c2-a2));
p1:=(a+b+dg1)/2;
s1:=Sqrt(p1*(p1-a)*(p1-b)*(p1-dg1));
p2:=(c+d+dg1)/2;
s2:=Sqrt(p2*(p2-c)*(p2-d)*(p2-dg1));
s:=s1+s2;
Edit10.Text:='Ïëîùà ÷îòèðèêóòíèêà= '+FloatToStr(s);
end;
end.