unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ExtCtrls, TeeProcs, TeEngine, Chart, StdCtrls, Series, Clipbrd;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    Image1: TImage;
    Chart1: TChart;
    Series1: TLineSeries;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  xn, xk, x, y, h, xomin, xomax, yomin, yomax : extended;

implementation

{$R *.dfm}

function f(x:extended):extended;
begin
f:=sin(x)/x;
end; 

procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text:='-2';
Edit2.Text:='-0,1';
Edit3.Text:='0,01';
Edit4.Text:='-2';
Edit5.Text:='-0,1';
Edit6.Text:='-3';
Edit7.Text:='3';
end;

procedure TForm1.Button1Click(Sender: TObject);
var xmax, ymax, yo : integer;
    hx, hy, dx : extended;
begin
  xn:=StrToFloat(Edit1.Text);
  xk:=StrToFloat(Edit2.Text);
  h:=StrToFloat(Edit3.Text);
  xomin:=StrToFloat(Edit4.Text);
  xomax:=StrToFloat(Edit5.Text);
  yomin:=StrToFloat(Edit6.Text);
  yomax:=StrToFloat(Edit7.Text);
  with Image1.Canvas do
     begin
     Pen.Width:=1;
     Pen.Color:=clBlack;
     Brush.Color:=clGreen;
     xmax:=Image1.Width;
     ymax:=Image1.Height;
     yo:=ymax div 2;
     MoveTo(0,yo);
     LineTo(xmax,yo);
     Pen.Color:=clRed;
     Pen.Width:=2;
     hx:=xmax/(xomax-xomin);
     hy:=ymax/(yomax-yomin);

     x:=xn;
     y:=f(x);
     dx:=0-x*hx;
     MoveTo(Round(x*hx+dx),Round(yo-y*hy));

     while x<=xk do
        begin
        x:=x+h;
        y:=f(x);
        LineTo(Round(x*hx+dx),Round(yo-y*hy));
        end;
    end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ClipBoard.Assign(Image1.Picture);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
  xn:=StrToFloat(Edit1.Text);
  xk:=StrToFloat(Edit2.Text);
  h:=StrToFloat(Edit3.Text);
  xomin:=StrToFloat(Edit4.Text);
  xomax:=StrToFloat(Edit5.Text);
  yomin:=StrToFloat(Edit6.Text);
  yomax:=StrToFloat(Edit7.Text);

  with Chart1 do
        begin
        LeftAxis.Automatic:=False;
        LeftAxis.Minimum:=yomin;
        LeftAxis.Maximum:=yomax;
        BottomAxis.Automatic:=False;
        BottomAxis.Minimum:=xomin;
        BottomAxis.Maximum:=xomax;
        SeriesList[0].Clear;

        x:=xn;
        while x<=xk do
                begin
                y:=f(x);
                SeriesList[0].AddXY(x,y);
                x:=x+h;
                end;
        end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
Chart1.CopyToClipboardMetafile(True);
end;

end.
