PageRenderTime 37ms CodeModel.GetById 17ms app.highlight 16ms RepoModel.GetById 2ms app.codeStats 0ms

/components/plotfunction/demo/expression/frmmain.pp

http://github.com/graemeg/lazarus
Pascal | 78 lines | 56 code | 16 blank | 6 comment | 0 complexity | 48b1f0a5f63d5215cd312fee477653a7 MD5 | raw file
 1unit frmmain;
 2
 3{$mode objfpc}{$H+}
 4
 5interface
 6
 7uses
 8  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
 9  ExtCtrls, StdCtrls, fpexprpars,exprplotpanel;
10
11type
12
13  { TMainForm }
14
15  TMainForm = class(TForm)
16    Button1: TButton;
17    EA: TEdit;
18    EB: TEdit;
19    EC: TEdit;
20    LEA: TLabel;
21    LEC: TLabel;
22    LEB: TLabel;
23    Panel1: TPanel;
24    PParams: TPanel;
25    procedure Button1Click(Sender: TObject);
26    procedure FormCreate(Sender: TObject);
27  private
28    { private declarations }
29    FPanel : TPlotExpressionPanel;
30  public
31    { public declarations }
32  end; 
33
34var
35  MainForm: TMainForm;
36
37implementation
38
39{$R *.lfm}
40
41{ TMainForm }
42
43procedure TMainForm.FormCreate(Sender: TObject);
44begin
45  FPanel:=TPlotExpressionPanel.Create(Self);
46  FPanel.Parent:=Panel1;
47  FPanel.Align:=alClient;
48  FPanel.Identifiers.AddFloatVariable('a',1.0);
49  FPanel.Identifiers.AddFloatVariable('b',0);
50  FPanel.Identifiers.AddFloatVariable('c',0);
51  FPanel.XAxis.Origin:=-30;
52  FPanel.XAxis.DrawZero:=True;
53  FPanel.YAxis.Caption.Alignment:=taCenter;
54  FPanel.YAxis.Origin:=-10;
55  FPanel.YAxis.DrawZero:=True;
56  FPanel.Expression:='a * (x * x) + b * x + c';
57  FPanel.Active:=True;
58  FPanel.Caption.Title:='Square function demo';
59  FPanel.Caption.Alignment:=taRightJustify;
60end;
61
62procedure TMainForm.Button1Click(Sender: TObject);
63
64Var
65  A,b,c : TExprFloat;
66
67begin
68  A:=StrToFLoat(EA.Text);
69  b:=StrToFLoat(EB.Text);
70  C:=StrToFLoat(EC.Text);
71  FPanel.Identifiers.IdentifierByName('a').AsFloat:=A;
72  FPanel.Identifiers.IdentifierByName('b').AsFloat:=B;
73  FPanel.Identifiers.IdentifierByName('c').AsFloat:=C;
74  FPanel.Invalidate;
75end;
76
77end.
78