Интегрирование системы отчетов в проект
AKReport

содержание

 

Пример "SimpleDemo" (...\Example\Delph\SimpleDemo.dpr')

В проекте "SimpleDemo.dpr" для вызова отчетов используется модуль "AKReportRunner".

Пример использования "AKReport" из Delphi.

unit AKReportRunner;

interface

procedure RPExecute(Name: string; Params: Variant; var Password:String; DBHandle:Integer=0);

implementation

uses

       Windows, ComObj, SysUtils, Report_TLB, ShellApi, Variants, Forms, Dialogs;

 

procedure RPExecute(Name: string; Params: Variant; var Password:String; DBHandle:Integer=0);

var

     FRP: IAKReport;

     i: integer;

     v: variant;

     ActiveWindow: Cardinal;

 

begin

      FRP := CreateOleObject('Report.AKReport') as IAKReport;

      try

            FRP.DebugLevel :=0;

            FRP.IniFileName := 'SimpleDemo.ini';

            // FRP.Objects.Item('HostAppl').Value := HostAppl; // COM Object

            FRP.DB.Params.Item('LibraryName').Value := 'gds32.dll';

            FRP.DB.Params.Item('SQLDialect').Value := 3;

            if DBHandle = 0 then

             begin

                   FRP.DB.Params.Item('DBName').Value :=

                               ExtractFilePath(Name) + 'Demo1.gdb';

                   FRP.DB.Params.Item('CharSet').Value := 'WIN1251';

                   FRP.DB.Params.Item('UserName').Value := 'SYSDBA';

                   FRP.DB.Params.Item('Password').Value := Password;

             end

             else

                   FRP.DB.DBHandle := integer(DBHandle);

            FRP.Open(Name);

            Password := FRP.DB.Params.Item('Password').Value;

            if FRP.ReportType = rtRtf then

                  FRP.DestinationDoc := ExtractFilePath(Application.ExeName)+ 'Temp\' + ChangeFileExt(ExtractFileName(Name),'.rtf')

            else

                  FRP.DestinationDoc := ExtractFilePath(Application.ExeName)+ 'Temp\' + ChangeFileExt(ExtractFileName(Name),'.xls');

            FRP.UserParams.SetAttr('Caption', _('Параметры отчёта'));

            FRP.UserParams.SetAttr('PersonalSettings', True);

            FRP.UserParams.SetAttr('Position', 'poScreenCenter');

            FRP.UserParams.SetAttr('FontSize', 12);

            FRP.UserParams.SetAttr('FontName', 'MS Sans Serif');

            FRP.UserParams.SetAttr('Color', 'clNavy');

            FRP.ShowType := stShowReport or stShowFinalMessage;

            if not VarIsEmpty(Params) then

            begin

                  for i := VarArrayLowBound(Params, 1) to VarArrayHighBound(Params, 1) do

                  begin

                         v := Params[i];

                         if SameText(v[0], 'ShowType') then

                               FRP.ShowType := v[1]

                         else

                               FRP.Params.Item(v[0]).Value := v[1];

                  end;

             end;

            if not FRP.Execute(True) then Exit;

            if (FRP.ShowType and stShowReport) <> 0 then

             begin

                  if (FRP.ReportType = rtRtf)

                   and ((FRP.ShowType and stUpdateFields) <> 0) then

                   begin

                         v := CreateOleObject('Word.Application');

                         v.Documents.Open(FRP.DestinationDoc);

                         v.ActiveDocument.Fields.Update;

                         v.Visible := True;

                   end

                   else

                         ShellExecute(0, 'open', PChar(string(FRP.DestinationDoc)), '', '', SW_SHOWNORMAL);

             end;

            if (FRP.ShowType and stShowFinalMessage) <> 0 then

             begin

                   ActiveWindow := GetForegroundWindow;

                   SetForegroundWindow(Application.Handle);

                   MsgInformation(_('Отчёт создан успешно.'));

                   SetForegroundWindow(ActiveWindow);

             end;

      finally

            FRP.Close;

            FRP := nil;

      end;      

end;

 

end.

 

содержание

Copyright © 2004: Alexander Krepky, Eugeny Makalish