File: lr_vbnd.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 (181 lines) | stat: -rw-r--r-- 4,111 bytes parent folder | download | duplicates (11)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181

{*****************************************}
{                                         }
{             FastReport v2.3             }
{     Select Band datasource dialog       }
{                                         }
{  Copyright (c) 1998-99 by Tzyganenko A. }
{                                         }
{*****************************************}

unit LR_VBnd;

interface

{$I LR_Vers.inc}

uses
  Classes, SysUtils, LResources,
  Forms, Controls, Graphics, Dialogs,
  Buttons, StdCtrls, ButtonPanel, Spin,Variants,

  LR_Class, LR_Intrp;

type

  { TfrVBandEditorForm }

  TfrVBandEditorForm = class(TForm)
    ButtonPanel1: TButtonPanel;
    edtRecCount: TSpinEdit;
    GroupBox1: TGroupBox;
    GroupBox2: TGroupBox;
    Label1: TLabel;
    CB1: TComboBox;
    LB1: TListBox;
    procedure FormCreate(Sender: TObject);
    procedure CB1Click(Sender: TObject);
    procedure LB1Click(Sender: TObject);
    procedure CB1Exit(Sender: TObject);
  private
    { Private declarations }
    Band: TfrBandView;
    List: TfrVariables;
    procedure FillCombo;
  public
    { Public declarations }
    procedure ShowEditor(t: TfrView);
  end;

var
  frVBandEditorForm: TfrVBandEditorForm;

implementation

{$R *.lfm}

uses LR_DSet, LR_Const, LR_Utils;

procedure TfrVBandEditorForm.ShowEditor(t: TfrView);
var
  i, j, n: Integer;
  s: String;
  t1: TfrView;
  b: Boolean;
begin
  Band := t as TfrBandView;
  List := TfrVariables.Create;
  try
    s := Band.Dataset;
    b := False;
    if Pos(';', s) = 0 then
      b := True;
    with frDesigner.Page do
    begin
      for i := 0 to Objects.Count - 1 do
      begin
        t1 := TfrView(Objects[i]);
        if (t1.Typ = gtBand) and not (TfrBandView(t1).BandType in
          [btReportTitle..btPageFooter, btOverlay, btCrossHeader..btCrossFooter]) then
        begin
          LB1.Items.Add(t1.Name + ': ' + frBandNames[TfrBandView(t1).BandType]);
          n := Pos(AnsiUpperCase(t1.Name) + '=', AnsiUpperCase(s));
          if n <> 0 then
          begin
            n := n + Length(t1.Name) + 1;
            j := n;
            while s[j] <> ';' do
              Inc(j);
            List[t1.Name] := Copy(s, n, j - n);
          end
          else
            if b then
              List[t1.Name] := s
            else
              List[t1.Name] := '0';
        end;
      end;
    end;
    
    if LB1.Items.Count = 0 then
      Exit;

    FillCombo;
    LB1.ItemIndex := 0;
    LB1Click(nil);

    if ShowModal = mrOk then
    begin
      CB1Exit(nil);
      frDesigner.BeforeChange;
      s := '';
      for i := 0 to List.Count - 1 do
      begin
        s := s + List.Name[i] + '=' + VarToStr(List.Value[i]) + ';';
      end;
      Band.DataSet := s;
    end;
  finally
    List.Free;
  end;
end;

procedure TfrVBandEditorForm.FillCombo;
begin
  frGetComponents(CurReport.Owner, TfrDataset, CB1.Items, nil);
  TStringList(CB1.Items).Sorted := False;
  TStringList(CB1.Items).Sort;
  CB1.Items.Insert(0, sVirtualDataset);
  CB1.Items.Insert(0, sNotAssigned);
end;

procedure TfrVBandEditorForm.FormCreate(Sender: TObject);
begin
  Caption := sVBandEditorFormCapt;
  GroupBox1.Caption := sVBandEditorFormBnd;
  GroupBox2.Caption := sVBandEditorFormDataSource;
  Label1.Caption := sVBandEditorFormRecordCount;
end;

procedure TfrVBandEditorForm.CB1Click(Sender: TObject);
begin
  frEnableControls([Label1, edtRecCount], CB1.ItemIndex = 1);
end;

procedure TfrVBandEditorForm.LB1Click(Sender: TObject);
var
  i: Integer;
  s: String;
begin
  s := LB1.Items[LB1.ItemIndex];
  s := Copy(s, 1, Pos(':', s) - 1);
  s := List[s];
  if (s <> '') and (s[1] in ['1'..'9']) then
  begin
    i := 1;
    edtRecCount.Text := s;
  end
  else
  begin
    i := CB1.Items.IndexOf(s);
    if i = -1 then
      i := CB1.Items.IndexOf(sNotAssigned);
  end;
  CB1.ItemIndex := i;
  CB1Click(nil);
end;

procedure TfrVBandEditorForm.CB1Exit(Sender: TObject);
var
  s: String;
begin
  s := LB1.Items[LB1.ItemIndex];
  s := Copy(s, 1, Pos(':', s) - 1);
  if CB1.ItemIndex = 1 then
    List[s] := edtRecCount.Text
  else
    List[s] := CB1.Items[CB1.ItemIndex];
end;

end.