File: lr_newrp.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 (171 lines) | stat: -rw-r--r-- 4,253 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171

{*****************************************}
{                                         }
{             FastReport v2.3             }
{             Template viewer             }
{                                         }
{  Copyright (c) 1998-99 by Tzyganenko A. }
{                                         }
{*****************************************}

unit LR_Newrp;

interface

{$I LR_Vers.inc}

uses
  Classes, SysUtils, LazFileUtils, LResources, Forms, Controls, Graphics, Dialogs,
  Buttons, StdCtrls, ExtCtrls, ButtonPanel, LR_Const;

type

  { TfrTemplForm }

  TfrTemplForm = class(TForm)
    ButtonPanel1: TButtonPanel;
    GroupBox1: TGroupBox;
    Memo1: TMemo;
    Image1: TImage;
    LB1: TListBox;
    procedure FormActivate(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
    procedure FormDeactivate(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure LB1DblClick(Sender: TObject);
  private
    FTemplatePath: String;
    function CheckLrtTemplate(const aFile:string): boolean;
  public
    DefaultTemplate: boolean;
    TemplName: String;
  end;

var
  frTemplForm: TfrTemplForm;

implementation
uses LR_Class, LR_Desgn;

{$R *.lfm}

procedure TfrTemplForm.FormActivate(Sender: TObject);
var
  SearchRec: TSearchRec;
  r: Word;
begin
  LB1.Items.Clear;
  R := FindFirstUTF8(FTemplatePath + '*.frt', faAnyFile, SearchRec);
  while R = 0 do
  begin
    if (SearchRec.Attr and faDirectory) = 0 then
      LB1.Items.Add(ChangeFileExt(SearchRec.Name, ''));
    R := FindNextUTF8(SearchRec);
  end;
  FindCloseUTF8(SearchRec);

  R := FindFirstUTF8(FTemplatePath + '*.lrt', faAnyFile, SearchRec);
  while R = 0 do
  begin
    if (SearchRec.Attr and faDirectory) = 0 then begin
      if CheckLrtTemplate(AppendPathDelim(FTemplatePath) + SearchRec.Name) then
        LB1.Items.AddObject(ChangeFileExt(SearchRec.Name, ''), Lb1);
    end;
    R := FindNextUTF8(SearchRec);
  end;
  FindCloseUTF8(SearchRec);

  Memo1.Lines.Clear;
  Image1.Picture.Clear;
  ButtonPanel1.OKButton.Enabled := False;
  LB1.Items.InsertObject(0, sTemplEmtpyRp, self);
end;

procedure TfrTemplForm.ListBox1Click(Sender: TObject);
var
  Index: Integer;
begin
  Index := LB1.ItemIndex;
  ButtonPanel1.OKButton.Enabled := Index <> -1;
  if ButtonPanel1.OKButton.Enabled then
  begin
    if LB1.Items.Objects[Index]=Self then
    begin
      Memo1.Lines.Text := sTemplEmptyDesc;
      Image1.Picture.Clear;
    end
    else
    begin
      if LB1.Items.Objects[Index]=LB1 then
      begin
        // lrt template
        if FileExistsUTF8(FTemplatePath + LB1.Items[Index] + '.lrt') then
          CurReport.LoadTemplateXML(FTemplatePath + LB1.Items[Index] + '.lrt',
            Memo1.Lines, Image1.Picture.Bitmap,False);
      end else
      begin
        // frt template
        if FileExistsUTF8(FTemplatePath + LB1.Items[Index] + '.frt') then
          CurReport.LoadTemplate(FTemplatePath + LB1.Items[Index] + '.frt',
            Memo1.Lines, Image1.Picture.Bitmap,False);
      end;
    end;
  end;
end;

procedure TfrTemplForm.LB1DblClick(Sender: TObject);
begin
  if ButtonPanel1.OKButton.Enabled then ModalResult := mrOk;
end;

function TfrTemplForm.CheckLrtTemplate(const aFile: string): boolean;
var
  F: TextFile;
  S:string;
begin
  Result := false;
  AssignFile(F, aFile);
  Reset(F);
  {$I-} ReadLn(F, s); {$I+}
  if IOResult=0 then
    Result := (pos('<?xml', s)=1);
  CloseFile(F);
end;

procedure TfrTemplForm.FormDeactivate(Sender: TObject);
var
  Index: Integer;
  aFileName: string;
begin
  DefaultTemplate := false;
  if ModalResult = mrOk then
  begin
    Index := LB1.ItemIndex;
    if LB1.Items.Objects[Index]=self then
      DefaultTemplate := true
    else
    begin
      aFileName := FTemplatePath + LB1.Items[LB1.ItemIndex];
      if LB1.Items.Objects[Index]=LB1 then
        aFileName := aFileName + '.lrt'
      else
        aFileName := aFileName + '.frt';
      if FileExists(aFileName) then
        TemplName := aFileName;
    end;
  end;
end;

procedure TfrTemplForm.FormCreate(Sender: TObject);
begin
  Caption := sTemplFormNewRp;
  GroupBox1.Caption := sTemplFormDesc;

  if frTemplateDir = '' then
    FTemplatePath := ''
  else
    FTemplatePath := AppendPathDelim(frTemplateDir);
end;

end.