lazarus/components/lazreport/source/lr_newrp.pas
jesus 118cc819c4 LazReport: New big patch from Alexey Lagunov (with small changes)
-------------------------------------------------------
Addfunction / frFuncStr
  - Fixed string functions - accounted for UTF8 strings

DialogControls
  - Fixed reports generation with built-in query mode, MDI (multiple reports open for viewing at the same time)
  - Fixed UNDO in editor
  - Added property HINT for dialog controls
  - A new component - TlrRadioGroup

lrOfficeImport
  - New tool reports designer to import data from a spreadsheet as a report template

source
  - The object TfrMemoView added new handlers
    - OnClick - Event when you click on TfrMemoView in playback mode built reports
    - OnMouseEnter - Event at the Enter of the mouse over TfrMemoView in playback mode built reports
    - OnMouseLeave - Event at the Leave of the mouse TfrMemoView in playback mode built reports

  - The object TfrMemoView added new properties
    - Cursor - the mouse cursor when moving over TfrMemoView in playback mode built reports
    - DetailReport - a reference to the detail-report - called when the user clicks the mouse on TfrMemoView in playback mode built reports

  - A mechanism to detail-report - call a detailed report of the current report
  - In ineterpretatore added new features (for compatibility with FastReport 2.5):
      - FINALPASS
      - CURY
      - PAGEHEIGH
      - PAGEWIDTH
  - In the reports, the editor started saving paramerov editor (the location of the Object Inspector, fonts)
  - In the reports, the editor corrected the addition of new tools (implemented a new tool - Import report template from excel/OpenOffice)
  - Editor of reports finalized Inspector data - now you can also insert variables
  - For export to txt implemented request form export options

images
  - Made in the resources icon tool insert fields in a report from the editor

Demo included (detail_reports)

And new extensions:
- import report template from calc/excel
- send email from report preview (for sending used local mail app, installed on user PC - in windows its TheBat! and Mozilla Thunderbird).
  In future I'm plan make direct send.

git-svn-id: trunk@46079 -
2014-08-28 04:10:20 +00:00

172 lines
4.1 KiB
ObjectPascal

{*****************************************}
{ }
{ FastReport v2.3 }
{ Template viewer }
{ }
{ Copyright (c) 1998-99 by Tzyganenko A. }
{ }
{*****************************************}
unit LR_Newrp;
interface
{$I LR_Vers.inc}
uses
Classes, SysUtils, FileUtil, 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.