1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108:
| unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls;
type TForm1 = class(TForm) ed_a: TEdit; ed_b: TEdit; ed_c: TEdit; edbereich: TEdit; edscalex: TEdit; edscaley: TEdit; btsolve: TButton; btreset: TButton; functionbox: TPaintBox; procedure btSolveClick(Sender: TObject); procedure ClearBox(); procedure btResetClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure functionboxPaint(Sender: TObject); private FHasFunction: Boolean; public end;
var Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.btSolveClick(Sender: TObject); var i,a,b,c,bereich,goright,goup: Integer; y1,y2,scalex,scaley: Real; begin bereich:= Round(StrToInt(edbereich.Text)/2); scalex:= StrToFloat(edscalex.Text); scaley:= StrToFloat(edscaley.Text); goright:= Round(FunctionBox.Width/2); goup:= Round(FunctionBox.Height/2); ClearBox; FHasFunction := true; For i:= -(bereich) to (bereich-1) do begin a:= StrToInt(ed_a.Text); b:= StrToInt(ed_b.Text); c:= StrToInt(ed_c.Text); y1:= (a*(i*i)+b*i+c); y2:= (a*((i+1)*(i+1))+b*(i+1)+c); with FunctionBox do begin Canvas.Pen.Color:= clBlack; Canvas.MoveTo(Round((i)*scalex + goright), Height-Round(y1*scaley) -goup); Canvas.LineTo(Round((i+1)*scalex + goright), Height-Round(y2*scaley) -goup); end; end; end;
procedure TForm1.ClearBox(); begin with FunctionBox do begin Canvas.Pen.Color:= clGray; Canvas.Brush.Color:= clWhite; Canvas.Rectangle(0,0,Width,Height); Canvas.MoveTo(0,round(Height/2)); Canvas.LineTo(Width,round(Height/2)); Canvas.MoveTo(round(Width/2),0); Canvas.LineTo(round(Width/2),Width); end; end;
procedure TForm1.FormCreate(Sender: TObject); begin FHasFunction := false; end;
procedure TForm1.functionboxPaint(Sender: TObject); begin if FHasFunction then btSolveClick(self) else ClearBox; end;
procedure TForm1.btResetClick(Sender: TObject); begin FHasFunction := false; invalidate; end;
end. |