Já tentei de varias maneiras para mostrar o relatorio quando se dá o duplo click no file da report guardada,agora tentei esta procedure no preview e não dá ...quer dizer a report é mostrada na perfeicão muda as paginas tudo correcto apenas quando executa retorna sempre um erro '''Access violation at address 0045D643 in module Gestor.exe read of adress 00000000.
Aqui a procedure....
procedure TfrmPreview.Resgata;
begin
QRPreview.QRPrinter.Load(ParamStr(1));
Caption := 'A gerar relatório, por favôr aguarde...';
if QRPreview.QRPrinter.Title = '' then
QRPreview.QRPrinter.Title := (ParamStr(1));
if QRPreview.QRPrinter.PageCount = 1 then
Self.Caption := QRPreview.QRPrinter.Title + ' - ' + IntToStr(QRPreview.QRPrinter.PageCount) + ' pagina'
else
Self.Caption := QRPreview.QRPrinter.Title + ' - ' + IntToStr(QRPreview.QRPrinter.PageCount) + ' paginas';
bPleaseInit := True;
Init;
end;
Esta roda em primeiro lugar Main Form.
procedure TVisualizar.QuickRep1Preview(Sender: TObject);
begin
Application.CreateForm(TfrmPreview, frmPreview);
with frmPreview do
begin
if ParamCount > 0 then
if FileExists(ParamStr(1)) then
begin
pQuickReport:= QuickRep1;
QRPreview.QRPrinter := TQRPrinter(Sender);
Resgata;
show;
end else
Caption := 'A gerar relatório, por favôr aguarde...';
pQuickReport:= QuickRep1;
QRPreview.QRPrinter := TQRPrinter(Sender);
Show;
end;
end;
end.
Aqui o code completo se executar o executavel ele roda na perfeição mas quando dou duplo click no report guardado...funciona mas dando o erro já descrito em cima.
Main form.
unit UnitVisualizar;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, Qrctrls, quickrpt, DBTables, ExtCtrls,qrprntr,Registry,ShlObj,
qrextra,qrhtml;
type
TVisualizar = class(TForm)
QuickRep1: TQuickRep;
QRBand1: TQRBand;
QRLabel1: TQRLabel;
QRLabel2: TQRLabel;
procedure FormCreate(Sender: TObject);
procedure QuickRep1Preview(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
WhichPreviewToUse: integer;
bCanPrint: boolean;
procedure RegistrarExtensaoQRP;
end;
var
Visualizar: TVisualizar;
implementation
uses Unit1;
{$R *.DFM}
procedure TVisualizar.RegistrarExtensaoQRP;
var
_reg: TRegistry;
begin
_reg := TRegistry.Create;
try
_reg.RootKey := HKEY_CLASSES_ROOT;
_reg.LazyWrite := False;
_reg.OpenKey('GestorV', True);
_reg.WriteString('', 'Relatórios do Gestor de portarias');
_reg.CloseKey;
_reg.OpenKey('GestorV\shell\open\command', True);
_reg.WriteString('', ParamStr(0) + ' "%1"');
_reg.CloseKey;
_reg.OpenKey('GestorV\DefaultIcon', True);
_reg.WriteString('', ParamStr(0) + ',0');
_reg.CloseKey;
_reg.OpenKey('.QRP', True);
_reg.WriteString('', 'GestorV');
_reg.CloseKey;
finally
_reg.free;
end;
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
end;
procedure TVisualizar.FormCreate(Sender: TObject);
begin
RegistrarExtensaoQRP;
WhichPreviewToUse := 0;
bCanPrint := True;
with QuickRep1 do
begin
preview;
end;
free;
end;
procedure TVisualizar.QuickRep1Preview(Sender: TObject);
begin
Application.CreateForm(TfrmPreview, frmPreview);
with frmPreview do
begin
if ParamCount > 0 then
if FileExists(ParamStr(1)) then
begin
pQuickReport:= QuickRep1;
QRPreview.QRPrinter := TQRPrinter(Sender);
Resgata;
show;
end else
Caption := 'A gerar relatório, por favôr aguarde...';
pQuickReport:= QuickRep1;
QRPreview.QRPrinter := TQRPrinter(Sender);
Show;
end;
end;
end.
Preview...
unit unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls, Spin, qrprntr,quickrpt,qrextra,qrhtml,
Buttons,Mylabel, TFlatSpeedButtonUnit,TypInfo,ShlObj;
type
TfrmPreview = class(TForm)
Panel1: TPanel;
QRPreview: TQRPreview;
sePage: TSpinEdit;
seZoom: TSpinEdit;
SaveDialogExport: TSaveDialog;
SpinEditCopies: TSpinEdit;
Panel2: TPanel;
sbFirstPage: TFlatSpeedButton;
sbPreviousPage: TFlatSpeedButton;
sbNextPage: TFlatSpeedButton;
sbLastPage: TFlatSpeedButton;
myLabel3d1: TmyLabel3d;
ZoomToFit: TFlatSpeedButton;
ZoomTo100: TFlatSpeedButton;
ZoomToWidth: TFlatSpeedButton;
PrintSetup: TFlatSpeedButton;
Print: TFlatSpeedButton;
myLabel3d2: TmyLabel3d;
lblCopies: TmyLabel3d;
Load: TFlatSpeedButton;
Save: TFlatSpeedButton;
BitBtnExit: TFlatSpeedButton;
Bevel1: TBevel;
procedure Init;
procedure sePageChange(Sender: TObject);
procedure seZoomChange(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure cmdExitClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure QRPreviewPageAvailable(Sender: TObject; PageNum: Integer);
procedure FormCreate(Sender: TObject);
procedure sbFirstPageClick(Sender: TObject);
procedure sbPreviousPageClick(Sender: TObject);
procedure sbNextPageClick(Sender: TObject);
procedure sbLastPageClick(Sender: TObject);
procedure ZoomToFitClick(Sender: TObject);
procedure ZoomTo100Click(Sender: TObject);
procedure ZoomToWidthClick(Sender: TObject);
procedure PrintSetupClick(Sender: TObject);
procedure PrintClick(Sender: TObject);
procedure SaveClick(Sender: TObject);
procedure CancelReport;
procedure LoadClick(Sender: TObject);
procedure BitBtnExitClick(Sender: TObject);
private
{ Private declarations }
public
pQuickreport : TQuickRep;
bPleaseInit : Boolean;
sTitle : string;
bCanPrint: boolean;
procedure Resgata;
{ Public declarations }
end;
var
frmPreview: TfrmPreview;
implementation
uses UnitVisualizar;
{$R *.DFM}
procedure TfrmPreview.sePageChange(Sender: TObject);
begin
Application.ProcessMessages;
QRPreview.PageNumber:=sePage.Value;
end;
procedure TfrmPreview.seZoomChange(Sender: TObject);
begin
Application.ProcessMessages;
QRPreview.Zoom:=seZoom.Value;
end;
procedure TfrmPreview.Init;
begin
if bPleaseInit then
begin
sePage.MaxValue := QRPreview.QRPrinter.PageCount;
sePage.MinValue := 1;
sePage.Value := 1;
QRPreview.Zoom:=100;
ZoomTo100.Down := True;
seZoom.Value:=QRPreview.Zoom;
bPleaseInit := False;
end;
end;
procedure TfrmPreview.FormShow(Sender: TObject);
var
OffSet: integer;
begin
bPleaseInit := True;
if not bCanPrint then
begin
Print.Enabled := bCanPrint;
Print.Visible := bCanPrint;
PrintSetup.Enabled := Print.Enabled;
PrintSetup.Visible := Print.Enabled;
lblCopies.Visible := Print.Enabled;
SpinEditCopies.Enabled := Print.Enabled;
SpinEditCopies.Visible := Print.Enabled;
OffSet := Load.Left - lblCopies.Left;
Load.Left := Load.Left - Offset;
Save.Left := Save.Left - Offset;
BitBtnExit.Left := BitBtnExit.Left - Offset;
end;
end;
procedure TfrmPreview.cmdExitClick(Sender: TObject);
begin
Close;
end;
procedure TfrmPreview.FormClose(Sender: TObject; var Action: TCloseAction);
begin
QRPreview.QRPrinter := nil;
Action := caFree;
release;
end;
procedure TfrmPreview.QRPreviewPageAvailable(Sender: TObject;
PageNum: Integer);
begin
Init;
sePage.MaxValue := PageNum;
if PageNum = 1 then
Caption := QRPreview.QRPrinter.Title + ' - 1 página'
else
Caption := QRPreview.QRPrinter.Title + ' - ' + IntToStr(PageNum) + ' páginas';
case QRPreview.QRPrinter.Status of
mpReady: Caption := Caption + ' pronto';
mpBusy: Caption := Caption + ' ocupado';
mpFinished: Caption := Caption + ' concluido';
end;
end;
procedure TfrmPreview.FormCreate(Sender: TObject);
begin
sbFirstPage.Glyph.Handle := LoadBitmap(hinstance, 'QRFIRSTPAGEBITMAP');
sbPreviousPage.Glyph.Handle := LoadBitmap(hinstance, 'QRPREVPAGEBITMAP');
sbNextPage.Glyph.Handle := LoadBitmap(hinstance, 'QRNEXTPAGEBITMAP');
sbLastPage.Glyph.Handle := LoadBitmap(hinstance, 'QRLASTPAGEBITMAP');
ZoomToFit.Glyph.Handle := LoadBitmap(hinstance, 'QRZOOMTOFITBITMAP');
ZoomTo100.Glyph.Handle := LoadBitmap(hinstance, 'QRZOOMTO100BITMAP');
ZoomToWidth.Glyph.Handle := LoadBitmap(hinstance, 'QRZOOMTOWIDTHBITMAP');
PrintSetup.Glyph.Handle := LoadBitmap(hinstance, 'QRPRINTSETUPBITMAP');
Print.Glyph.Handle := LoadBitmap(hinstance, 'QRPRINTBITMAP');
Load.Glyph.Handle := LoadBitmap(hinstance, 'QROPENBITMAP');
Save.Glyph.Handle := LoadBitmap(hinstance, 'QRSAVEBITMAP');
{ Load strings for hints }
//ZoomToFit.Hint := LoadStr( SqrZoomToFit );
//ZoomTo100.Hint := LoadStr( SqrZoom100 );
//ZoomToWidth.Hint := LoadStr( SqrZoomToWidth );
//sbFirstPage.Hint := LoadStr( SqrFirstPage );
//sbLastPage.Hint := LoadStr( SqrLastPage );
//sbPreviousPage.Hint := LoadStr( SqrPrevPage );
//sbNextPage.Hint := LoadStr( SqrNextPage );
//PrintSetup.Hint := LoadStr( SqrPrinterSetup );
//Print.Hint := LoadStr( SqrPrintReport );
//Save.Hint := LoadStr( SqrSaveReport );
//Load.Hint := LoadStr( SqrLoadReport );
WindowState := wsMaximized;
FormStyle := fsStayOnTop;
bCanPrint := True;
end;
procedure TfrmPreview.sbFirstPageClick(Sender: TObject);
begin
Application.ProcessMessages;
sePage.Value := 1;
QRPreview.PageNumber:=sePage.Value;
end;
procedure TfrmPreview.sbPreviousPageClick(Sender: TObject);
begin
Application.ProcessMessages;
if sePage.Value > 1 then
begin
sePage.Value := sePage.Value - 1;
QRPreview.PageNumber:=sePage.Value;
end;
end;
procedure TfrmPreview.sbNextPageClick(Sender: TObject);
begin
Application.ProcessMessages;
if sePage.Value < QRPreview.QRPrinter.PageCount then
begin
sePage.Value := sePage.Value + 1;
QRPreview.PageNumber:=sePage.Value;
end;
end;
procedure TfrmPreview.sbLastPageClick(Sender: TObject);
begin
Application.ProcessMessages;
sePage.Value := QRPreview.QRPrinter.PageCount;
QRPreview.PageNumber:=sePage.Value;
end;
procedure TfrmPreview.ZoomToFitClick(Sender: TObject);
begin
Application.ProcessMessages;
QRPreview.ZoomToFit;
seZoom.Value:=QRPreview.Zoom;
end;
procedure TfrmPreview.ZoomTo100Click(Sender: TObject);
begin
Application.ProcessMessages;
QRPreview.Zoom:=100;
seZoom.Value:=QRPreview.Zoom;
end;
procedure TfrmPreview.ZoomToWidthClick(Sender: TObject);
begin
Application.ProcessMessages;
QRPreview.ZoomToWidth;
seZoom.Value:=QRPreview.Zoom;
end;
procedure TfrmPreview.PrintSetupClick(Sender: TObject);
begin
{
With 2.0j, QuickReport will set the report's tag property to -1 if the
user cancels the printersetup. By checking for this value, we can call
the print method directly from setup if the users selects OK
}
with pQuickReport do
begin
tag := -1; { Just in case you are using an older version }
PrinterSetup;
if tag = 0 then
print;
end;
end;
procedure TfrmPreview.PrintClick(Sender: TObject);
begin
Print.Enabled := False;
QRPreview.qrprinter.Print;
Print.Enabled := True;
end;
procedure TfrmPreview.SaveClick(Sender: TObject);
var
aExportFilter : TQRExportFilter;
{$ifndef win32}
FileExt : string;
I : integer;
{$endif}
begin
aExportFilter := nil;
with TSaveDialog.Create(Application) do
try
Filter := QRExportFilterLibrary.SaveDialogFilterString;
{ DefaultExt := cQRPDefaultExt;}
if Execute then
begin
{$ifdef win32}
if FilterIndex = 1 then
begin
if Pos('.', Filename) = 0 then
Filename := Filename + '.qrp';
QRPreview.QRPrinter.Save(Filename);
end
else
begin
try
aExportFilter := TQRExportFilterLibraryEntry(
QRExportFilterLibrary.Filters[FilterIndex - 2]).ExportFilterClass.Create(Filename);
QRPreview.QRPrinter.ExportToFilter(aExportFilter);
finally
aExportFilter.Free
end
end
{$else}
FileExt := ExtractFileExt(Filename);
if copy(FileExt, 1, 1) = '.' then delete(FileExt, 1, 1);
if (FileExt = '') or (FileExt = cQRPDefaultExt) then
QRPreview.QRPrinter.Save(Filename)
else
begin
for I := 0 to QRExportFilterLibrary.Filters.Count - 1 do
begin
if TQRExportFilterLibraryEntry(QRExportFilterLibrary.Filters[I]).Extension = FileExt then
try
aExportFilter := TQRExportFilterLibraryEntry(
QRExportFilterLibrary.Filters[I]).ExportFilterClass.Create(Filename);
QRPreview.QRPrinter.ExportToFilter(aExportFilter);
finally
aExportFilter.Free;
end;
end;
end;
{$endif}
end;
finally
Free;
end;
end;
procedure TfrmPreview.CancelReport;
begin
if pQuickReport.qrprinter.status = mpBusy then
if MessageDlg('Fechar visualizacão ?', mtConfirmation, mbOKCancel,0) = mrOK then
begin
QRPrinter.Cancel;
QRPreview.qrprinter := nil;
end;
end;
procedure TfrmPreview.LoadClick(Sender: TObject);
begin
with TOpenDialog.Create(Application) do
try
Filter := 'QuickReport files (*.qrp)|*.qrp';
if Execute then
if FileExists(FileName) then
begin
QRPreview.QRPrinter.Load(Filename);
QRPreview.PageNumber := 1;
QRPreview.PreviewImage.PageNumber := 1;
if QRPreview.QRPrinter.Title = '' then
QRPreview.QRPrinter.Title := Filename;
if QRPreview.QRPrinter.PageCount = 1 then
Self.Caption := QRPreview.QRPrinter.Title + ' - ' + IntToStr(QRPreview.QRPrinter.PageCount) + ' pagina'
else
Self.Caption := QRPreview.QRPrinter.Title + ' - ' + IntToStr(QRPreview.QRPrinter.PageCount) + ' paginas';
bPleaseInit := True;
Init;
end
else
ShowMessage('Este ficheiro não pode ser visualizado: ' + FileName);
finally
free;
end;
end;
procedure TfrmPreview.BitBtnExitClick(Sender: TObject);
begin
Application.terminate;
end;
procedure TfrmPreview.Resgata;
begin
QRPreview.QRPrinter.Load(ParamStr(1));
Caption := 'A gerar relatório, por favôr aguarde...';
if QRPreview.QRPrinter.Title = '' then
QRPreview.QRPrinter.Title := (ParamStr(1));
if QRPreview.QRPrinter.PageCount = 1 then
Self.Caption := QRPreview.QRPrinter.Title + ' - ' + IntToStr(QRPreview.QRPrinter.PageCount) + ' pagina'
else
Self.Caption := QRPreview.QRPrinter.Title + ' - ' + IntToStr(QRPreview.QRPrinter.PageCount) + ' paginas';
bPleaseInit := True;
Init;
end;
end.
Não consigo que funcione logo abrindo o report guardado sem dar erro, já tentei o Debuguer mas tb não encontro o erro...quando dou duplo click na report guardada vejo pelo gestor de tarefas do win que a memória fica em carga e depois de fazer ok na mensagem do erro ela liberta ...mas porquê e onde???
Pergunta
António44
Já tentei de varias maneiras para mostrar o relatorio quando se dá o duplo click no file da report guardada,agora tentei esta procedure no preview e não dá ...quer dizer a report é mostrada na perfeicão muda as paginas tudo correcto apenas quando executa retorna sempre um erro '''Access violation at address 0045D643 in module Gestor.exe read of adress 00000000.
Aqui a procedure....
Esta roda em primeiro lugar Main Form. Aqui o code completo se executar o executavel ele roda na perfeição mas quando dou duplo click no report guardado...funciona mas dando o erro já descrito em cima. Main form. Preview...Não consigo que funcione logo abrindo o report guardado sem dar erro, já tentei o Debuguer mas tb não encontro o erro...quando dou duplo click na report guardada vejo pelo gestor de tarefas do win que a memória fica em carga e depois de fazer ok na mensagem do erro ela liberta ...mas porquê e onde???
agradecido.
Abraço
Editado por António44Link para o comentário
Compartilhar em outros sites
10 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.