|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
|||
|
|||
нужна маленькая поправка!
Код:
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Grids, StdCtrls; type TForm1 = class(TForm) Button1: TButton; StringGrid1: TStringGrid; Button2: TButton; Edit1: TEdit; Edit2: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; i:integer; x,a:real; b:string; h: array [1..5] of real = (1, 0.2, 0.1, 0.01, 0.001); p1,p2,p3: array [1..5] of real; implementation {$R *.dfm} Function y(x:real):real; begin y:=ln((2*x*x+x-3)/(3*x*x+15*x+12)); end; procedure TForm1.Button1Click(Sender: TObject); begin x:=strtoint(edit1.Text); for i:= 1 to 5 do begin p1[i]:=(y(x+h[i])-y(x))/h[i]; p2[i]:=(y(x)-y(x-h[i]))/h[i]; p3[i]:=(y(x+h[i])-y(x-h[i]))/(2*h[i]); end; for i:=1 to 5 do begin a:=p1[i]; str(a:4:4,b); StringGrid1.Cells[i,1]:=b; a:=p2[i]; str(a:4:4,b); StringGrid1.Cells[i,2]:=b; a:=p3[i]; str(a:4:4,b); StringGrid1.Cells[i,3]:=b; begin StringGrid1.Cells[0,0]:='h'; StringGrid1.Cells[0,1]:='p1'; StringGrid1.Cells[0,2]:='p2'; StringGrid1.Cells[0,3]:='p3'; StringGrid1.Cells[1,0]:='1'; StringGrid1.Cells[2,0]:='0.2'; StringGrid1.Cells[3,0]:='0.1'; StringGrid1.Cells[4,0]:='0.01'; StringGrid1.Cells[5,0]:='0.001'; end; end; end; procedure TForm1.Button2Click(Sender: TObject); begin close; end; end. есть такой код, как сделать что бы h задавалось с клавиатуры(h это шаг) Последний раз редактировалось Falkone, 25.05.2010 в 03:12. |
#2
|
|||
|
|||
Добавить TEdit на форму и в обработчике клика по кнопке дописать:
Код:
procedure TForm1.Button1Click(Sender: TObject); begin h:=strtoint(edit3.Text); ... |
#3
|
|||
|
|||
писал такое, выдает ошибку на h:=strtoint(edit2.Text); (ошибка incompatible types array integer)
|
#4
|
||||
|
||||
Было-бы странно если не выдавал. У вас описание h:
Код:
h: array [1..5] of real = (1, 0.2, 0.1, 0.01, 0.001); Код:
Var hh: TStringList; i: Integer; begin hh := TStringList.Create; hh.Delimiter := ' '; hh.DelimitedText := Edit1.Text; for i := 0 to hh.Count - 1 do h[i] := StrToFloat(hh.Strings[i]); Жизнь такова какова она есть и больше никакова. Помогаю за спасибо. |
#5
|
|||
|
|||
ничего у меня толком не вышло, может кто то поправить мне сам код?
мне нужно что бы я мог задавать шаг(h), все что мне нужно! |