Проверьте пож. код. Не выводит ничего. Пишет ошибок нет.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
lbl1: TLabel;
lbl3: TLabel;
lbl4: TLabel;
lbl5: TLabel;
lbl6: TLabel;
lbl7: TLabel;
lbl8: TLabel;
edt1: TEdit;
edt2: TEdit;
edt3: TEdit;
edt4: TEdit;
lbl12: TLabel;
lbl13: TLabel;
procedure Btn1Click (Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure Ed1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
procedure Osik(x0,y0:Integer);
procedure Postroenie(T1,T2,R1,R2:real);
end;
var
Form1: TForm1;
X0,Y0:Integer;
T1,T2,R1,R2:real;
implementation
{$R *.dfm}
procedure TForm1.Osik(x0,y0:Integer);
var
i,x,y:Integer;
begin
Canvas.Pen.Width:=2;
Canvas.Pen.Color:=clBlack;
Canvas.MoveTo(x0,y0);
Canvas.LineTo(x0+400,y0);
Canvas.MoveTo(x0+400,y0);
Canvas.LineTo(x0+400-10,y0-5);
Canvas.MoveTo(x0+400,y0);
Canvas.LineTo(x0+400-10,y0+5);
lbl4.Left:=x0+390;
lbl4.Top:=y0+10;
lbl5.Left:=x0+350;
lbl5.Top:=y0+10;
lbl6.Left:=x0;
lbl6.Top:=y0+10;
lbl7.Left:=x0-25;
lbl7.Top:=y0-10;
lbl8.Left:=x0-25;
lbl8.Top:=y0-105;
Canvas.MoveTo(x0,y0);
Canvas.LineTo(x0,y0-150);
Canvas.MoveTo(x0,y0-150);
Canvas.LineTo(x0-5,y0-150+10);
Canvas.MoveTo(x0,y0-150);
Canvas.LineTo(x0+5,y0-150+10);
lbl3.Left:=x0-30;
lbl3.Top:=y0-150;
Canvas.Pen.Width:=1;
x:=x0;
for i:=1 to 10 do
begin
x:=x+35;
Canvas.MoveTo(x,y0-3);
Canvas.LineTo(x,y0+3);
end;
y:=y0;
for i:=1 to 5 do
begin
y:=y-20;
Canvas.MoveTo(x0-3,y);
Canvas.LineTo(x0+3,y);
end;
end;
procedure TForm1.Postroenie(T1,T2,R1,R2:real);
var
x,y:Integer;
Kx,Ky,x1,y1,P,C1,Sag:Real;
begin
Canvas.Pen.Width;
Canvas.Pen.Color;
Sag:=(R2-R1)/500;
C1:=(T1-T2)/(Ln(R2/R1));
Kx:=(R2-R1)/350;
if T1>T2 then
Ky:=T1/100
else
Ky:=T2/100;
x1:=R1;
y1:=T1;
Canvas.MoveTo(x0+Round((x1-R1)/Kx),y0-Round(y1/Ky));
repeat
y:=Round(y1/Ky);
x:=Round((x1-R1)/Kx);
Canvas.LineTo(x0+x,y0-y);
x1:=x1+Sag;
y1:=(T1+C1*ln(R1/x1));
until x1>R2;
P:=4*Pi-C1;
lbl1.Caption:='Ìîùíîñòü èñòî÷íèêà:='+FloatToStrF(P,ffGeneral,5,1)+'Âò';
lbl4.Caption:='r';
lbl3.Caption:='T(r)';
lbl5.Caption:=FloatToStrF(R2,ffGeneral,4,1);
lbl6.Caption:=FloatToStrF(R1,ffGeneral,4,1);
if T1>T2 then
begin
lbl7.Caption:=FloatToStrF(T2,ffGeneral,4,1);
lbl8.Caption:=FloatToStrF(T1,ffGeneral,4,1);
end
else
begin
lbl7.Caption:=FloatToStrF(T1,ffGeneral,4,1);
lbl8.Caption:=FloatToStrF(T2,ffGeneral,4,1);
end;
end;
procedure TForm1.Btn1Click(Sender: TObject);
var
Code1,Code2,Code3,Code4:Integer;
begin
Repaint;
Val (edt1.Text,T1,Code1);
Val (edt2.Text,T2,Code2);
Val (edt3.Text,R1,Code3);
Val (edt4.Text,R2,Code4);
if (Code4 or Code3 or Code2 or Code1)<>0 then
begin
edt1.SetFocus;
MessageDlg('Ââåäèòå ïîæàëóéñòà çíà÷åíèå!',mtError,[mbOK],0);
end
else
Postroenie(T1,T2,R1,R2);
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
x0:=100;
y0:=200;
Osik (X0,Y0);
end;
procedure TForm1.Ed1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9',#8,'.']) then
begin
Key:=#0;
MessageBeep($FFFFFFFF);
end;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
lbl1: TLabel;
lbl3: TLabel;
lbl4: TLabel;
lbl5: TLabel;
lbl6: TLabel;
lbl7: TLabel;
lbl8: TLabel;
edt1: TEdit;
edt2: TEdit;
edt3: TEdit;
edt4: TEdit;
lbl12: TLabel;
lbl13: TLabel;
procedure Btn1Click (Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure Ed1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
procedure Osik(x0,y0:Integer);
procedure Postroenie(T1,T2,R1,R2:real);
end;
var
Form1: TForm1;
X0,Y0:Integer;
T1,T2,R1,R2:real;
implementation
{$R *.dfm}
procedure TForm1.Osik(x0,y0:Integer);
var
i,x,y:Integer;
begin
Canvas.Pen.Width:=2;
Canvas.Pen.Color:=clBlack;
Canvas.MoveTo(x0,y0);
Canvas.LineTo(x0+400,y0);
Canvas.MoveTo(x0+400,y0);
Canvas.LineTo(x0+400-10,y0-5);
Canvas.MoveTo(x0+400,y0);
Canvas.LineTo(x0+400-10,y0+5);
lbl4.Left:=x0+390;
lbl4.Top:=y0+10;
lbl5.Left:=x0+350;
lbl5.Top:=y0+10;
lbl6.Left:=x0;
lbl6.Top:=y0+10;
lbl7.Left:=x0-25;
lbl7.Top:=y0-10;
lbl8.Left:=x0-25;
lbl8.Top:=y0-105;
Canvas.MoveTo(x0,y0);
Canvas.LineTo(x0,y0-150);
Canvas.MoveTo(x0,y0-150);
Canvas.LineTo(x0-5,y0-150+10);
Canvas.MoveTo(x0,y0-150);
Canvas.LineTo(x0+5,y0-150+10);
lbl3.Left:=x0-30;
lbl3.Top:=y0-150;
Canvas.Pen.Width:=1;
x:=x0;
for i:=1 to 10 do
begin
x:=x+35;
Canvas.MoveTo(x,y0-3);
Canvas.LineTo(x,y0+3);
end;
y:=y0;
for i:=1 to 5 do
begin
y:=y-20;
Canvas.MoveTo(x0-3,y);
Canvas.LineTo(x0+3,y);
end;
end;
procedure TForm1.Postroenie(T1,T2,R1,R2:real);
var
x,y:Integer;
Kx,Ky,x1,y1,P,C1,Sag:Real;
begin
Canvas.Pen.Width;
Canvas.Pen.Color;
Sag:=(R2-R1)/500;
C1:=(T1-T2)/(Ln(R2/R1));
Kx:=(R2-R1)/350;
if T1>T2 then
Ky:=T1/100
else
Ky:=T2/100;
x1:=R1;
y1:=T1;
Canvas.MoveTo(x0+Round((x1-R1)/Kx),y0-Round(y1/Ky));
repeat
y:=Round(y1/Ky);
x:=Round((x1-R1)/Kx);
Canvas.LineTo(x0+x,y0-y);
x1:=x1+Sag;
y1:=(T1+C1*ln(R1/x1));
until x1>R2;
P:=4*Pi-C1;
lbl1.Caption:='Ìîùíîñòü èñòî÷íèêà:='+FloatToStrF(P,ffGeneral,5,1)+'Âò';
lbl4.Caption:='r';
lbl3.Caption:='T(r)';
lbl5.Caption:=FloatToStrF(R2,ffGeneral,4,1);
lbl6.Caption:=FloatToStrF(R1,ffGeneral,4,1);
if T1>T2 then
begin
lbl7.Caption:=FloatToStrF(T2,ffGeneral,4,1);
lbl8.Caption:=FloatToStrF(T1,ffGeneral,4,1);
end
else
begin
lbl7.Caption:=FloatToStrF(T1,ffGeneral,4,1);
lbl8.Caption:=FloatToStrF(T2,ffGeneral,4,1);
end;
end;
procedure TForm1.Btn1Click(Sender: TObject);
var
Code1,Code2,Code3,Code4:Integer;
begin
Repaint;
Val (edt1.Text,T1,Code1);
Val (edt2.Text,T2,Code2);
Val (edt3.Text,R1,Code3);
Val (edt4.Text,R2,Code4);
if (Code4 or Code3 or Code2 or Code1)<>0 then
begin
edt1.SetFocus;
MessageDlg('Ââåäèòå ïîæàëóéñòà çíà÷åíèå!',mtError,[mbOK],0);
end
else
Postroenie(T1,T2,R1,R2);
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
x0:=100;
y0:=200;
Osik (X0,Y0);
end;
procedure TForm1.Ed1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9',#8,'.']) then
begin
Key:=#0;
MessageBeep($FFFFFFFF);
end;
end;
end.
Процедурка Osik - это, конечно, хорошо, но неплохо бы ее вызвать в процедурке FormPaint...
Цитата: wanja
Процедурка Osik - это, конечно, хорошо, но неплохо бы ее вызвать в процедурке FormPaint...
Признаюсь вам, это моя первая программа на DElphi, не могли бы вы более подробно описать, что нужно мне переделать в программе. =)
Посмотрите пож. прикрепленный файл, я PrtSreen-ном сфотографировала, что он мне выводит на экран.
И вставил ваш код, после implementation.
Поправил Ed1KeyPress на edt1KeyPress.
Отформатировал код (а то у вас убожество какое-то) и получил:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
lbl1: TLabel;
lbl3: TLabel;
lbl4: TLabel;
lbl5: TLabel;
lbl6: TLabel;
lbl7: TLabel;
lbl8: TLabel;
edt1: TEdit;
edt2: TEdit;
edt3: TEdit;
edt4: TEdit;
lbl12: TLabel;
lbl13: TLabel;
procedure FormPaint(Sender: TObject);
procedure edt1KeyPress(Sender: TObject; var Key: Char);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Osik(x0, y0: Integer);
procedure Postroenie(T1, T2, R1, R2: real);
end;
var
Form1: TForm1;
x0, y0: Integer;
T1, T2, R1, R2: real;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.Osik(x0, y0: Integer);
var
i, x, y: Integer;
begin
Canvas.Pen.Width := 2;
Canvas.Pen.Color := clBlack;
Canvas.MoveTo(x0, y0);
Canvas.LineTo(x0 + 400, y0);
Canvas.MoveTo(x0 + 400, y0);
Canvas.LineTo(x0 + 400 - 10, y0 - 5);
Canvas.MoveTo(x0 + 400, y0);
Canvas.LineTo(x0 + 400 - 10, y0 + 5);
lbl4.Left := x0 + 390;
lbl4.Top := y0 + 10;
lbl5.Left := x0 + 350;
lbl5.Top := y0 + 10;
lbl6.Left := x0;
lbl6.Top := y0 + 10;
lbl7.Left := x0 - 25;
lbl7.Top := y0 - 10;
lbl8.Left := x0 - 25;
lbl8.Top := y0 - 105;
Canvas.MoveTo(x0, y0);
Canvas.LineTo(x0, y0 - 150);
Canvas.MoveTo(x0, y0 - 150);
Canvas.LineTo(x0 - 5, y0 - 150 + 10);
Canvas.MoveTo(x0, y0 - 150);
Canvas.LineTo(x0 + 5, y0 - 150 + 10);
lbl3.Left := x0 - 30;
lbl3.Top := y0 - 150;
Canvas.Pen.Width := 1;
x := x0;
for i := 1 to 10 do
begin
x := x + 35;
Canvas.MoveTo(x, y0 - 3);
Canvas.LineTo(x, y0 + 3);
end;
y := y0;
for i := 1 to 5 do
begin
y := y - 20;
Canvas.MoveTo(x0 - 3, y);
Canvas.LineTo(x0 + 3, y);
end;
end;
procedure TForm1.Postroenie(T1, T2, R1, R2: real);
var
x, y: Integer;
Kx, Ky, x1, y1, P, C1, Sag: real;
begin
Canvas.Pen.Width;
Canvas.Pen.Color;
Sag := (R2 - R1) / 500;
C1 := (T1 - T2) / (Ln(R2 / R1));
Kx := (R2 - R1) / 350;
if T1 > T2 then
Ky := T1 / 100
else
Ky := T2 / 100;
x1 := R1;
y1 := T1;
Canvas.MoveTo(x0 + Round((x1 - R1) / Kx), y0 - Round(y1 / Ky));
repeat
y := Round(y1 / Ky);
x := Round((x1 - R1) / Kx);
Canvas.LineTo(x0 + x, y0 - y);
x1 := x1 + Sag;
y1 := (T1 + C1 * Ln(R1 / x1));
until x1 > R2;
P := 4 * Pi - C1;
lbl1.Caption := 'Мощность источника:=' + FloatToStrF(P, ffGeneral, 5, 1)
+ ' Вт';
lbl4.Caption := 'r';
lbl3.Caption := 'T(r)';
lbl5.Caption := FloatToStrF(R2, ffGeneral, 4, 1);
lbl6.Caption := FloatToStrF(R1, ffGeneral, 4, 1);
if T1 > T2 then
begin
lbl7.Caption := FloatToStrF(T2, ffGeneral, 4, 1);
lbl8.Caption := FloatToStrF(T1, ffGeneral, 4, 1);
end
else
begin
lbl7.Caption := FloatToStrF(T1, ffGeneral, 4, 1);
lbl8.Caption := FloatToStrF(T2, ffGeneral, 4, 1);
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
Code1, Code2, Code3, Code4: Integer;
begin
Repaint;
Val(edt1.Text, T1, Code1);
Val(edt2.Text, T2, Code2);
Val(edt3.Text, R1, Code3);
Val(edt4.Text, R2, Code4);
if (Code4 or Code3 or Code2 or Code1) <> 0 then
begin
edt1.SetFocus;
MessageDlg('введите числа', mtError, [mbOK], 0);
end
else
Postroenie(T1, T2, R1, R2);
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
x0 := 100;
y0 := 200;
Osik(x0, y0);
end;
procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if not(Key in ['0' .. '9', #8, '.']) then
begin
Key := #0;
MessageBeep($FFFFFFFF);
end;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
lbl1: TLabel;
lbl3: TLabel;
lbl4: TLabel;
lbl5: TLabel;
lbl6: TLabel;
lbl7: TLabel;
lbl8: TLabel;
edt1: TEdit;
edt2: TEdit;
edt3: TEdit;
edt4: TEdit;
lbl12: TLabel;
lbl13: TLabel;
procedure FormPaint(Sender: TObject);
procedure edt1KeyPress(Sender: TObject; var Key: Char);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure Osik(x0, y0: Integer);
procedure Postroenie(T1, T2, R1, R2: real);
end;
var
Form1: TForm1;
x0, y0: Integer;
T1, T2, R1, R2: real;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.Osik(x0, y0: Integer);
var
i, x, y: Integer;
begin
Canvas.Pen.Width := 2;
Canvas.Pen.Color := clBlack;
Canvas.MoveTo(x0, y0);
Canvas.LineTo(x0 + 400, y0);
Canvas.MoveTo(x0 + 400, y0);
Canvas.LineTo(x0 + 400 - 10, y0 - 5);
Canvas.MoveTo(x0 + 400, y0);
Canvas.LineTo(x0 + 400 - 10, y0 + 5);
lbl4.Left := x0 + 390;
lbl4.Top := y0 + 10;
lbl5.Left := x0 + 350;
lbl5.Top := y0 + 10;
lbl6.Left := x0;
lbl6.Top := y0 + 10;
lbl7.Left := x0 - 25;
lbl7.Top := y0 - 10;
lbl8.Left := x0 - 25;
lbl8.Top := y0 - 105;
Canvas.MoveTo(x0, y0);
Canvas.LineTo(x0, y0 - 150);
Canvas.MoveTo(x0, y0 - 150);
Canvas.LineTo(x0 - 5, y0 - 150 + 10);
Canvas.MoveTo(x0, y0 - 150);
Canvas.LineTo(x0 + 5, y0 - 150 + 10);
lbl3.Left := x0 - 30;
lbl3.Top := y0 - 150;
Canvas.Pen.Width := 1;
x := x0;
for i := 1 to 10 do
begin
x := x + 35;
Canvas.MoveTo(x, y0 - 3);
Canvas.LineTo(x, y0 + 3);
end;
y := y0;
for i := 1 to 5 do
begin
y := y - 20;
Canvas.MoveTo(x0 - 3, y);
Canvas.LineTo(x0 + 3, y);
end;
end;
procedure TForm1.Postroenie(T1, T2, R1, R2: real);
var
x, y: Integer;
Kx, Ky, x1, y1, P, C1, Sag: real;
begin
Canvas.Pen.Width;
Canvas.Pen.Color;
Sag := (R2 - R1) / 500;
C1 := (T1 - T2) / (Ln(R2 / R1));
Kx := (R2 - R1) / 350;
if T1 > T2 then
Ky := T1 / 100
else
Ky := T2 / 100;
x1 := R1;
y1 := T1;
Canvas.MoveTo(x0 + Round((x1 - R1) / Kx), y0 - Round(y1 / Ky));
repeat
y := Round(y1 / Ky);
x := Round((x1 - R1) / Kx);
Canvas.LineTo(x0 + x, y0 - y);
x1 := x1 + Sag;
y1 := (T1 + C1 * Ln(R1 / x1));
until x1 > R2;
P := 4 * Pi - C1;
lbl1.Caption := 'Мощность источника:=' + FloatToStrF(P, ffGeneral, 5, 1)
+ ' Вт';
lbl4.Caption := 'r';
lbl3.Caption := 'T(r)';
lbl5.Caption := FloatToStrF(R2, ffGeneral, 4, 1);
lbl6.Caption := FloatToStrF(R1, ffGeneral, 4, 1);
if T1 > T2 then
begin
lbl7.Caption := FloatToStrF(T2, ffGeneral, 4, 1);
lbl8.Caption := FloatToStrF(T1, ffGeneral, 4, 1);
end
else
begin
lbl7.Caption := FloatToStrF(T1, ffGeneral, 4, 1);
lbl8.Caption := FloatToStrF(T2, ffGeneral, 4, 1);
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
var
Code1, Code2, Code3, Code4: Integer;
begin
Repaint;
Val(edt1.Text, T1, Code1);
Val(edt2.Text, T2, Code2);
Val(edt3.Text, R1, Code3);
Val(edt4.Text, R2, Code4);
if (Code4 or Code3 or Code2 or Code1) <> 0 then
begin
edt1.SetFocus;
MessageDlg('введите числа', mtError, [mbOK], 0);
end
else
Postroenie(T1, T2, R1, R2);
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
x0 := 100;
y0 := 200;
Osik(x0, y0);
end;
procedure TForm1.edt1KeyPress(Sender: TObject; var Key: Char);
begin
if not(Key in ['0' .. '9', #8, '.']) then
begin
Key := #0;
MessageBeep($FFFFFFFF);
end;
end;
end.
Заполнив все Edit-ы числапи и нажав кнопку, получил:
Кажись, все тип-топ.
Программа компилируется и запускается и даже работает (возможно даже правильно - лень вникать).