File: lr_editsqldbparamsunit.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 (150 lines) | stat: -rw-r--r-- 3,689 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
unit lr_EditSQLDBParamsUnit;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel,
  StdCtrls, Buttons, ExtCtrls, lr_SQLQuery, DB;

type

  { Tlr_EditSQLDBParamsForm }

  Tlr_EditSQLDBParamsForm = class(TForm)
    BitBtn1: TBitBtn;
    ButtonPanel1: TButtonPanel;
    ComboBox1: TComboBox;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    ListBox1: TListBox;
    Memo1: TMemo;
    Splitter1: TSplitter;
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
  private
    FParams:TQueryParamList;
    EditItem:integer;
  public
    procedure LoadParamList(AParams:TQueryParamList);
    procedure SaveParamList(AParams:TQueryParamList);
  end;

implementation
uses lr_expres;

{$R *.lfm}

{ Tlr_EditSQLDBParamsForm }

procedure Tlr_EditSQLDBParamsForm.ListBox1Click(Sender: TObject);
var
  P:TQueryParam;
begin
  if (ListBox1.Items.Count>0) and (ListBox1.ItemIndex > -1) and (ListBox1.ItemIndex<ListBox1.Items.Count) then
  begin
    if EditItem>-1 then
    begin
      P:=TQueryParam(FParams[EditItem]);
      case ComboBox1.ItemIndex of
        0:P.ParamType:=ftString; //String
        1:P.ParamType:=ftInteger; //Integer
        2:P.ParamType:=ftFloat; //Float
        3:P.ParamType:=ftDateTime; //DateTime
      else
        P.ParamType:=ftUnknown;
      end;
      P.ParamValue:=Memo1.Text;
    end;
    EditItem:=ListBox1.ItemIndex;
    P:=TQueryParam(FParams[EditItem]);
    case P.ParamType of
      ftString:ComboBox1.ItemIndex:=0; //String
      ftInteger:ComboBox1.ItemIndex:=1; //Integer
      ftFloat:ComboBox1.ItemIndex:=2; //Float
      ftDateTime:ComboBox1.ItemIndex:=3; //DateTime
    else
      ComboBox1.ItemIndex:=-1;
    end;
    Memo1.Text:=P.ParamValue;
  end;
end;

procedure Tlr_EditSQLDBParamsForm.BitBtn1Click(Sender: TObject);
var
  EF:TlrExpresionEditorForm;
begin
  EF:=TlrExpresionEditorForm.Create(Application);
  if EF.ShowModal = mrOk then
    Memo1.Text:=EF.ResultExpresion;
  EF.Free;
end;

procedure Tlr_EditSQLDBParamsForm.FormCloseQuery(Sender: TObject;
  var CanClose: boolean);
begin
  if ModalResult = mrOk then
    ListBox1Click(nil);
end;

procedure Tlr_EditSQLDBParamsForm.FormCreate(Sender: TObject);
begin
{  Caption:=slrEditParamsForm_Caption;
  GroupBox1.Caption:=slrEditParamsForm_ParamsList;
  GroupBox2.Caption:=slrEditParamsForm_ParamValue;
  Label1.Caption:=slrEditParamsForm_ParamType;
  Label2.Caption:=slrEditParamsForm_ParamValue;
  BitBtn1.Caption:=slrEditParamsForm_SelectExpresion;}
  //
  FParams:=TQueryParamList.Create;
end;

procedure Tlr_EditSQLDBParamsForm.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FParams);
end;

procedure Tlr_EditSQLDBParamsForm.LoadParamList(AParams: TQueryParamList);
var
  i:integer;
  P:TQueryParam;
begin
  FParams.Clear;
  ListBox1.Items.Clear;
  for i:=0 to AParams.Count - 1 do
  begin
    P:=TQueryParam(AParams[i]);
    FParams.Add(P.ParamType, P.ParamName, P.ParamValue);
    ListBox1.Items.Add(P.ParamName);
  end;
  EditItem:=-1;
  if ListBox1.Items.Count > 0 then
  begin
    ListBox1.ItemIndex:=0;
    ListBox1Click(nil);
  end;
end;

procedure Tlr_EditSQLDBParamsForm.SaveParamList(AParams: TQueryParamList);
var
  i:integer;
  P, P1:TQueryParam;
begin
  for i:=0 to FParams.Count - 1 do
  begin
    P:=TQueryParam(FParams[i]);
    P1:=TQueryParam(AParams[i]);
    P1.ParamType:=P.ParamType;
    P1.ParamName:=P.ParamName;
    P1.ParamValue:=P.ParamValue;
  end;
end;

end.