File: lr_funct_editor_unit1.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (130 lines) | stat: -rw-r--r-- 2,727 bytes parent folder | download | duplicates (8)
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
121
122
123
124
125
126
127
128
129
130
unit lr_funct_editor_unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, LR_Class, LR_Const, 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);
    procedure FormCreate(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.FormCreate(Sender: TObject);
begin
  Caption:=sFunctionEditor;
  GroupBox1.Caption:=sArguments;
  Label3.Caption:=sArgument1;
  Label4.Caption:=sArgument2;
  Label5.Caption:=sArgument3;
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.