Recent

Author Topic: Question about LazReport SaveDialog  (Read 2440 times)

dsyrios

  • Jr. Member
  • **
  • Posts: 57
Question about LazReport SaveDialog
« on: August 01, 2014, 08:52:02 am »
How can I set parameter "InitialDir" at a LazReport SaveDialog ?
For example I have
    MyInitialDir : string;
    MyReport : TfrReport;
when I call
    MyReport.ShowReport;
I want to pass   
  SaveDialog.InitialDir := MyInitialDir;
and then to save it at the spesific directory
 
The following declarations are in units LR_View & LP_Class.
 
  TfrPreviewForm = class(TForm)
  {...}
    SaveDialog: TSaveDialog;
  {...}
  end;

  TfrPreview = class(TPanel)
  {...}
   FWindow: TfrPreviewForm;
   {...}
  end;

  TfrReport = class(TComponent)
  {...}
   FPreview: TfrPreview;
   {...}
  end;

Thanks in advance. 
 
Laz 2.0.2/FPC 3.0.4/ win10/64
Laz 2.0.0/FPC 3.0.4/ mint-mate 19.1

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Question about LazReport SaveDialog
« Reply #1 on: August 01, 2014, 09:33:10 am »
In the current implementation it is not supported. If you follow the showReport code you will see that it first prepares the report and the calles the showPreparedReport which has the following code (in lazarus 1.2.4 fpc 2.6.4)
Code: [Select]
procedure TfrReport.ShowPreparedReport;
var
  s: String;
  p: TfrPreviewForm;
begin
  {$IFDEF DebugLR}
  DebugLnEnter('TfrReport.ShowPreparedReport INIT');
  {$ENDIF}
  CurReport := Self;
  MasterReport := Self;
  DocMode := dmPrinting;
  if EMFPages.Count = 0 then Exit;
  s := sPreview;
  if Title <> '' then
    s := s + ' - ' + Title;
   
  if not (csDesigning in ComponentState) and Assigned(Preview) then
  begin
    Preview.Connect(Self);
  end
  else
  begin
    p := TfrPreviewForm.Create(nil);
    p.BorderIcons:=p.BorderIcons - [biMinimize];
    {$IFDEF DebugLR}
    DebugLn('1 TfrPreviewForm.visible=%s',[BooLToStr(p.Visible)]);
    {$ENDIF}
    p.Caption := s;
    {$IFDEF DebugLR}
    DebugLn('2 TfrPreviewForm.visible=%s',[BooLToStr(p.Visible)]);
    {$ENDIF}
    if ExportFilename<>'' then
      p.SaveDialog.FileName := ExportFilename;
    p.Show_Modal(Self);
  end;
  {$IFDEF DebugLR}
  DebugLnExit('TfrReport.ShowPreparedReport DONE');
  {$ENDIF}
end;

as you can see your self there 2 main problems on the above code
1) The preview you set does not give you access to the underline preview form or its save dialog.
2) if you leave the preview empty the form create is not accesible outside the ShowPreparedReport method.

having said that I'd like to inform you that you can set the exportfilename public variable, which sets the savedialog.filename which might have the effect you are after and might not.

Two bonus problems when no preview is assigned by the end user, in my code that is always.

1) it seems that the ShowPreparedReport has a memory leak as it never frees the created preview form.
2) regardless of the value of ModalPreview report's property the preview window will always be modal.

I need to download the latest development version to take a closer look when I get some free time.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

dsyrios

  • Jr. Member
  • **
  • Posts: 57
Re: Question about LazReport SaveDialog
« Reply #2 on: August 01, 2014, 03:58:35 pm »
Thanks very much, Taaz !
I'll skip it temporary with the "wrong way" ...
a global var MyInitialDir : string;   at unit LR_View
and at
procedure TfrPreviewForm.SaveBtnClick(Sender: TObject);
{...}
SaveDialog.InitialDir:= MyInitialDir;
{...}
Laz 2.0.2/FPC 3.0.4/ win10/64
Laz 2.0.0/FPC 3.0.4/ mint-mate 19.1

 

TinyPortal © 2005-2018