File: lr_funct_editor_unit1.pas

package info (click to toggle)
lazarus 1.2.4%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 170,220 kB
  • ctags: 115,165
  • sloc: pascal: 1,386,898; xml: 257,878; sh: 2,935; java: 603; makefile: 549; perl: 297; sql: 174; ansic: 137
file content (120 lines) | stat: -rw-r--r-- 2,451 bytes parent folder | download | duplicates (2)
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
109
110
111
112
113
114
115
116
117
118
119
120
unit lr_funct_editor_unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, LR_Class, EditBtn, Buttons, ButtonPanel;

type

  { TLR_FunctEditor1Form }

  TLR_FunctEditor1Form = class(TForm)
    BitBtn3: TBitBtn;
    BitBtn4: TBitBtn;
    BitBtn5: TBitBtn;
    ButtonPanel1: TButtonPanel;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Panel1: TPanel;
    procedure BitBtn5Click(Sender: TObject);
  private
    FParCount:integer;
    FD:TfrFunctionDescription;
  public
    procedure SetFunctionDescription(AFD:TfrFunctionDescription);
    function ResultText:string;
  end; 

implementation

{$R *.lfm}

uses lr_expres, lr_utils;

{ TLR_FunctEditor1Form }


procedure TLR_FunctEditor1Form.BitBtn5Click(Sender: TObject);
var
  EF:TlrExpresionEditorForm;
begin
  EF:=TlrExpresionEditorForm.Create(Application);
  try
    if EF.ShowModal = mrOk then
    case (Sender as TComponent).Tag of
      1:Edit1.Text:=EF.ResultExpresion;
      2:Edit2.Text:=EF.ResultExpresion;
      3:Edit3.Text:=EF.ResultExpresion;
    end;
  finally
    EF.Free;
  end;
end;


procedure TLR_FunctEditor1Form.SetFunctionDescription(AFD: TfrFunctionDescription);
var
  S, S1:string;
  i:integer;
begin

  // TODO: context sensitive inpunts, for example for
  //       bandname use the list of available bands.

  FD:=AFD;
  S:=FD.funDescription;
  S1:=Copy(S, 1, Pos('/', S)-1);

  FParCount:=0;
  for i:=1 to Length(S1) do
    if S1[i]='<' then
      Inc(FParCount);

  Label1.Caption:=S1;
  Delete(S, 1, Pos('/', S));
  Label2.Caption:=S;

  Label3.Enabled:=FParCount>0;
  Edit1.Enabled:=FParCount>0;
  BitBtn3.Enabled:=FParCount>0;
  
  Label4.Enabled:=FParCount>1;
  Edit2.Enabled:=FParCount>1;
  BitBtn4.Enabled:=FParCount>0;

  Label5.Enabled:=FParCount>2;
  Edit3.Enabled:=FParCount>2;
  BitBtn5.Enabled:=FParCount>0;

end;

function TLR_FunctEditor1Form.ResultText: string;
begin
  Result:='';
  if FParCount>0 then
   Result:=Result + '[' + lrGetUnBrackedStr(Edit1.Text) + ']';

  if FParCount>1 then
   Result:=Result + ', [' + lrGetUnBrackedStr(Edit2.Text) + ']';

  if FParCount>2 then
   Result:=Result + ', [' + lrGetUnBrackedStr(Edit3.Text) + ']';
   
  if FParCount>0 then
    Result:='('+Result+')';
  Result:=FD.funName + Result;
end;

end.