home *** CD-ROM | disk | FTP | other *** search
- { First attempt at a Delphi Visual component for R&R runtime }
- { You are free to distribute and use this file as you wish with this header }
- { Please email any comments/enhancements to cbrooksbank@cix.compulink.co.uk }
-
- { Needs R&R Report Writer - SQL Edition V6.0 - Concentric Data Systems, Inc.}
- { Author Chris Brooksbank (cbrooksbank@cix.compulink.co.uk) }
- { Written : June 1995 }
- { Needs rrsqlint }
-
- unit ReportRR;
-
- interface
-
- uses
- SysUtils,WinTypes,WinProcs,Messages,Classes,Graphics,Controls,Forms,
- Dialogs,rrsqlint,DsgnIntf;
-
- type
- TRP6Filename = class(TStringProperty)
- function GetAttributes: TPropertyAttributes; override;
- procedure Edit; override;
- end;
- TReportRR = class(TComponent)
- private
- { Private declarations }
- fAuthor:String;
- fAppName:String;
- fBeginPage: Longint;
- fCopies: Longint;
- fDataDir : String;
- fDataSource: String;
- fDisplayErrors: Boolean;
- fDisplayStatus: Boolean;
- fEndPage: LongInt;
- fErrorCode: Char;
- fErrorMessage: String;
- fExportDest: Char;
- fFields: TStringList;
- fFilter: String;
- fFilterUsage: Char;
- fGroupFields: TStringList;
- fImageDir : String;
- fJoins: TStringList;
- fLibName: String;
- fMasterTableName: String;
- fMemoName: String;
- fOutputDest: Char;
- fOutputFile: String;
- fPassword: String;
- fPreventEscape: Boolean;
- fPrinterName: String;
- fPrinterPort: String;
- fReplaces: TStringList;
- fRepName:String;
- fReportPick: Boolean;
- fSortFields: TStringList;
- fStatusEveryPage: Boolean;
- fSuppressTitle: Boolean;
- fTestPattern: Boolean;
- fUserName: String;
- fUserParams: TStringList;
- fWait: Boolean;
- fWinBorderStyle: Integer;
- fWinControlBox: Boolean;
- fWinHeight: Integer;
- fWinLeft:Integer;
- fWinMaxButton: Boolean;
- fWinMinButton: Boolean;
- fWinParentHandle: Integer;
- fWinTitle: String;
- fWinTop: Integer;
- fWinWidth:Integer;
- procedure SetRepName(NewRepName: String);
- procedure SetLibName(NewLibName:String);
- procedure LoadReportInfo;
- procedure LoadFields(hReport:Integer);
- procedure LoadGroupFields(hReport:Integer);
- procedure LoadSortFields(hReport:Integer);
- procedure LoadJoins(hReport:Integer);
- protected
- { Protected declarations }
- public
- { Public declarations }
- constructor Create(Aowner:TComponent); override;
- destructor Free;
- procedure execute;
- published
- { Published declarations }
- property AppName: String read fAppName write fAppName;
- property Author: String read fAuthor write fAuthor;
- property BeginPage: Longint read fBeginPage write fBeginPage default 1;
- property Copies: Longint read fCopies write fCopies default 1;
- property DataSource: String read fDataSource write fDataSource;
- property DisplayErrors: Boolean read fDisplayErrors write fDisplayErrors;
- property DisplayStatus: Boolean read fDisplayStatus write fDisplayStatus;
- property EndPage: Longint read fEndPage write fEndPage default 999999;
- property ExportDest: Char read fExportDest write fExportDest;
- property Fields: TStringList read fFields write fFields;
- property Filter: String read fFilter write fFilter;
- property FilterUsage: Char read fFilterUsage write fFilterUsage;
- property GroupFields: TStringList read fGroupFields write fGroupFields;
- property Joins: TStringList read fJoins write fJoins;
- property MasterTableName: String read fMasterTableName write fMasterTableName;
- property MemoName: String read fMemoName write fMemoName;
- property OutputDest: Char read fOutputDest write fOutputDest default 'D';
- property OutputFile: String read fOutputFile write fOutputFile;
- property Password: String read fPassword write fPassword;
- property PreventEscape: Boolean read fPreventEscape write fPreventEscape;
- property PrinterName: String read fPrinterName write fPrinterName;
- property PrinterPort: String read fPrinterPort write fPrinterPort;
- property ReportLibrary: String read fLibName write setLibName;
- property ReportName: String read fRepName write setRepName;
- property SortFields: TStringList read fSortFields write fSortFields;
- property StatusEveryPage: Boolean read fStatusEveryPage write fStatusEveryPage;
- property SuppressTitle: Boolean read fSuppressTitle write fSuppressTitle;
- property TestPattern: Boolean read fTestPattern write fTestPattern;
- property UserName: String read fUserName write fUserName;
- property Wait: Boolean read fWait write fWait;
- property WinBorderStyle:Integer read fWinBorderStyle write fWinBorderStyle default 2;
- property WinControlBox: Boolean read fWinControlBox write fWinControlBox;
- property WinHeight: Integer read fWinHeight write fWinHeight;
- property WinLeft: Integer read fWinLeft write fWinLeft;
- property WinMaxButton: Boolean read fWinMaxButton write fWinMaxButton default true;
- property WinMinButton: Boolean read fWinMinButton write fWinMinButton default true;
- property WinParentHandle: Integer read fWinParentHandle write fWinParentHandle;
- property WinTitle: String read fWinTitle write fWinTitle;
- property WinTop:Integer read fWinTop write fWinTop;
- property WinWidth:Integer read fWinWidth write fWinWidth;
- end;
-
-
- procedure Register;
-
- implementation
-
- constructor TReportRR.create(AOwner:Tcomponent);
- begin
- inherited create(AOwner);
-
- fAppName:=application.EXEname;
-
- fFields:=TStringList.Create;
- fJoins:=TStringList.Create;
- fGroupFields:=TStringList.Create;
- fSortFields:=TStringList.Create;
- fUserParams:=TStringList.Create;
-
- fAuthor:='cbrooksbank@cix.compulink.co.uk';
- fBeginPage:=1;
- fEndPage:=999999;
- fOutputDest:='D';
- fCopies:=1;
- fWinBorderStyle:=2;
- fWinMaxButton:=true;
- fWinMinButton:=true;
- end;
-
- destructor TReportRR.Free;
- begin
- fFields.Free;
- fJoins.Free;
- fGroupFields.Free;
- fSortFields.Free;
- fUserParams.Free;
- inherited Free;
- end;
-
-
- procedure Register;
- begin
- RegisterComponents('Data Access', [TReportRR]);
- RegisterPropertyEditor(TypeInfo(String),TReportRR,'flibname',TRP6FileName);
- end;
-
- function TRP6FileName.GetAttributes: TPropertyAttributes;
- begin
- Result:=[paDialog];
- end;
-
- procedure TRP6FileName.Edit;
- { Custom property editor for selecting a R&R library file }
- var
- LibOpen: TOpenDialog;
- begin
- LibOpen:=TOpenDialog.Create(Application);
- LibOpen.Filter:='R&R Report Librarys|*.RP6';
- LibOpen.Free;
- end;
-
- procedure TReportRR.LoadReportInfo;
- { When reportname or libname change load various information }
- { from the report. E.G. fields,sort-fields,group-fields,joins e.t.c.}
- var
- hMyReport:Integer;
- MyApp_,MyLib_,MyRep_: array[0..255] of char;
- begin
-
- if ((fRepName<>'') and (fLibName<>'')) then begin
-
- fFields.Clear;
- fSortFields.Clear;
- fJoins.Clear;
- fGroupFields.Clear;
-
- StrPCopy(MyApp_,application.EXEname);
- StrPCopy(MyLib_,fLibName);
- StrPCopy(MyRep_,fRepName);
-
- InitRunTimeInstance;
- hMyReport:=ChooseReport(MyApp_,MyLib_,MyRep_,sizeof(MyRep_));
-
- try
- if hMyReport>0 then begin
- LoadFields(hMyReport);
- LoadGroupFields(hMyReport);
- LoadSortFields(hMyReport);
- LoadJoins(hMyReport);
- if fRepName='' then fRepName:=StrPas(MyRep_);
- end;
- finally
- EndReport(hMyReport);
- EndRunTimeInstance;
- end;
- end;
-
- end;
-
-
- procedure TReportRR.LoadFields(hReport:Integer);
- var
- FieldName:Array[0..30] of char;
- begin
- GetFirstFieldName(hReport,FieldName,Sizeof(FieldName));
- fFields.Add(StrPas(FieldName));
- while GetNextFieldName(hReport,FieldName,Sizeof(FieldName)) do
- fFields.Add(StrPas(FieldName));
- end;
-
- procedure TReportRR.LoadGroupFields(hReport:Integer);
- var
- GroupField:Array[0..30] of char;
- begin
- GetFirstGroupField(hReport,GroupField,Sizeof(GroupField));
- fGroupFields.Add(StrPas(GroupField));
- while GetNextGroupField(hReport,GroupField,Sizeof(GroupField)) do
- fGroupFields.Add(StrPas(GroupField));
- end;
-
- procedure TReportRR.LoadSortFields(hReport:Integer);
- var
- SortField:Array[0..30] of char;
- begin
- GetFirstSortField(hReport,SortField,Sizeof(SortField));
- fSortFields.Add(StrPas(SortField));
- while GetNextSortField(hReport,SortField,Sizeof(SortField)) do
- fSortFields.Add(StrPas(SortField));
- end;
-
- procedure TReportRR.LoadJoins(hReport:Integer);
- begin
- end;
-
- procedure TReportRR.SetLibName(NewLibName: String);
- begin
- fLibName:=NewLibName;
- LoadReportInfo;
- end;
-
-
- procedure TReportRR.SetRepName(NewRepName: String);
- begin
- fRepName:=NewRepName;
- LoadReportInfo;
- end;
-
-
- procedure TReportRR.Execute;
- var
- { Handle of report }
- hReport: Integer;
-
- { Temp vars to hold Pchar versions of String properties }
- Appname_,LibName_,RepName_,DataSource_,PrinterName_: array[0..255] of char;
- PrinterPort_,PassWord_,UserName_: array[0..30] of char;
- filter_: array[0..255] of char;
- MasterTableName_,MemoName_,OutputFile_,WinTitle_: array[0..255] of char;
-
- { Flags returned after report was run }
- ECode:Integer;
- cmdshow: Integer;
- PageCount:LongInt;
- EMsg:array[0..255] of char;
-
- ErrorMess: String;
-
- begin
- {Run the report }
-
- { Convert Pascal type strings to C++ strings as expected by DLL }
- StrPCopy(Appname_,fAppname);
- StrPCopy(DataSource_,fDataSource);
- StrPCopy(Filter_,fFilter);
- StrPCopy(Libname_,fLibName);
- StrPCopy(MasterTableName_,fMasterTableName);
- StrPCopy(MemoName_,fMemoName);
- StrPCopy(OutputFile_,fOutputFile);
- StrPCopy(Password_,fPassword);
- StrPCopy(Printername_,fPrinterName);
- StrPCopy(PrinterPort_,fPrinterPort);
- StrPCopy(RepName_,fRepName);
- StrPCopy(UserName_,fUserName);
- StrPCopy(WinTitle_,fWinTitle);
-
- { Initialise RSREPORT.DLL and get a handle for the report }
- InitRuntimeInstance;
- hReport:=chooseReport(AppName_,LibName_,RepName_,Sizeof(RepName_));
-
- { Pass all the propertys to RSREPORT.DLL }
- SetBeginPage(hReport,fBeginPage);
- SetCopies(hReport,fCopies);
- SetDataSource(hReport,DataSource_);
- SetDisplayErrors(hReport,fDisplayErrors);
- SetDisplayStatus(hReport,FDisplayStatus);
- SetEndPage(hReport,fEndPage);
- SetExportDest(hReport,fExportDest);
- SetFilter(hReport,Filter_);
- SetFilterUsage(hReport,fFilterUsage);
- SetMasterTableName(hReport,MasterTableName_);
- SetMemoName(hReport,MemoName_);
- SetOutputDest(hReport,fOutputDest);
- SetOutPutFile(hReport,OutputFile_);
- SetPassword(hReport,Password_);
- SetPreventEscape(hReport,fPreventEscape);
- SetPrinter(hReport,PrinterName_);
- SetPrinterPort(hReport,PrinterPort_);
- SetStatusEveryPage(hReport,fStatusEveryPage);
- SetTestPattern(hReport,fTestPattern);
- SetUserName(hReport,Username_);
- SetWinBorderStyle(hReport,fWinBorderStyle);
- SetWinControlBox(hReport,fWinControlBox);
- SetWinHeight(hReport,fWinHeight);
- SetWinLeft(hReport,fWinLeft);
- SetWinMaxButton(hReport,fWinMaxButton);
- SetWinMinButton(hReport,fWinMinButton);
- SetWinParentHandle(hReport,fWinParentHandle);
- SetWinTitle(hReport,WinTitle_);
- SetWinTop(hReport,fWinTop);
- SetWinWidth(hReport,fWinWidth);
-
- { Run the report and then clean up }
- cmdshow:=SW_SHOWNORMAL;
- ExecRunTime(hReport,fWait,cmdshow,@ECode,@PageCount,EMsg,sizeof(EMsg));
- EndReport(hReport);
- endRunTimeInstance;
- end;
-
- end.