Solved

How to call R&R reports from Delphi 2007

Posted on 2011-03-08
21
526 Views
Last Modified: 2012-05-11
Hi,

I am starting a new project using Delphi 2007 and R&R 12.5 (having used R&R for the past 20 years interfacing via control files, rrwrun.exe and xbase++)

I have read the documentation and created a very simple test to run one report. However, I am unable to get R&R to run the report within Delphi by using the R&R dll.

My test code is attached.

I must be missing some thing basic but as I have never done this before with R&R/DLL I am at a loss to determine where I am going wrong.

Can anyone please help with this?

Best regards,

Bruce

procedure TForm1.Button3Click(Sender: TObject);
var
// var for error
lpszMsg: PChar; //PInteger; //PAnsiChar;
mSize: Integer;
lpiCode: PInteger; // PAnsiChar;
Ertn: LongBool; //PChar;

// for choosereport
RepHandle: integer;
AppName: Pchar;
LibName: Pchar;
LSize: Integer;
Rep: Pchar;
RSize: Integer;
//ReportReturnCode: integer;
bWait: Boolean;
FsCmdShow: integer;
RptErrMsg: PAnsiChar;
lpiECode: PInteger;
lplPageCount: PLongInt;
emSize: integer;
RtnBol: LongBool;

begin
lpszMsg:= '';
mSize:= 200;
lpiCode:= 0;
//
AppName := nil;
LibName := nil;
LSize := 0;
Rep := 'c:\dev\edm2000\rr\wards.rrw';
Rsize := 40;
//
emSize := 200;
bWait := true;
//RtnBol:=false;
FsCmdShow:= 0;
RptErrMsg:='';
lpiECode:=nil;
lplPageCount:=nil;

// Start R&R routine
resetErrorInfo(0); // clears the error buffer

RepHandle:= chooseReport(AppName,LibName,LSize,Rep,RSize);
// Check for errors
getErrorInfo(RepHandle,lpszMsg,mSize,lpiCode);
// Set runtime settings here...
RtnBol := execRuntime(RepHandle,bWait,FsCmdShow,lpiECode,lplPageCount,RptErrMsg,emSize);
Ertn := getErrorInfo(RepHandle,lpszMsg,mSize,lpiCode);
if RtnBol then
begin;
showmessage('Report returned True')
end

else;

begin;
showmessage('Report returned False: ' + lpszMsg)
// now need to GetError to see what is wrong
GetErrorInfo();

end;

end;

Open in new window

0
Comment
Question by:Bruce-Dev
  • 10
  • 5
  • 5
  • +1
21 Comments
 
LVL 24

Expert Comment

by:jimyX
ID: 35069360
Can't test codes at the moment but did some syntax correction on your code:
procedure TForm1.Button3Click(Sender: TObject);
var
// var for error
  lpszMsg: PChar; //PInteger; //PAnsiChar;
  mSize: Integer;
  lpiCode: PInteger; // PAnsiChar;
  Ertn: LongBool; //PChar;

  // for choosereport
  RepHandle: integer;
  AppName: Pchar;
  LibName: Pchar;
  LSize: Integer;
  Rep: Pchar;
  RSize: Integer;
  //ReportReturnCode: integer;
  bWait: Boolean;
  FsCmdShow: integer;
  RptErrMsg: PAnsiChar;
  lpiECode: PInteger;
  lplPageCount: PLongInt;
  emSize: integer;
  RtnBol: LongBool;
begin
  lpszMsg:= '';
  mSize:= 200;
  lpiCode:= 0;
  //
  AppName := nil;
  LibName := nil;
  LSize := 0;
  Rep := 'c:\dev\edm2000\rr\wards.rrw';
  Rsize := 40;
  //
  emSize := 200;
  bWait := true;
  //RtnBol:=false;
  FsCmdShow:= 0;
  RptErrMsg:='';
  lpiECode:=nil;
  lplPageCount:=nil;

  // Start R&R routine
  resetErrorInfo(0); // clears the error buffer

  RepHandle:= chooseReport(AppName,LibName,LSize,Rep,RSize);
  // Check for errors
  getErrorInfo(RepHandle,lpszMsg,mSize,lpiCode);
  // Set runtime settings here...
  RtnBol := execRuntime(RepHandle,bWait,FsCmdShow,lpiECode,lplPageCount,RptErrMsg,emSize);
  Ertn := getErrorInfo(RepHandle,lpszMsg,mSize,lpiCode);
  if RtnBol then
    begin
      showmessage('Report returned True');
    end
  else
    begin
      showmessage('Report returned False: ' + lpszMsg);
      // now need to GetError to see what is wrong
      GetErrorInfo();
    end;
end;

Open in new window

0
 
LVL 19

Expert Comment

by:Thommy
ID: 35069384
Do you know how to use DLL's in Delphi???

Creating and Using DLLs from Delphi
http://delphi.about.com/od/windowsshellapi/a/dll_basics.htm


You have to declare external functions for interfacing the R&R Reports DLL.

I have found this example of such a wrapper DLL for R&R 6.5:

Delphi Components For R&R Version 6.5 XBASE and SQL Editions
http://www.programmersheaven.com/download/5890/3/ZipView.aspx

But You'd better use Unit rrdecl32.pas, that comes with your R&R version 12.5.

Insert rrdecl32 into your USES list, make sure that R&R DLL is loaded and you should have no problem calling the specific R&R functions...
0
 

Author Comment

by:Bruce-Dev
ID: 35069464
Jimyx,

I have just tried your tidy-up of my original code and receive the following message:

"Address violation at address 100132D7 in module 'RRRPT32.DLL'. Write of address 004AE1AC"

(I had to disable the GetErrorInfo() as it would not compile with this line in)

This is the type of error I was receiving before.  Do you have any further suggestions?

Best regards,

Bruce
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35069497
Please Read chapter 3 "Accessing the Viewer DLL".
http://www.livewarepub.com/ftp/Documentation/R&R%20Xbase/Xbasedev.pdf

It is straighforward. Please tell me if there is anything you DO NOT understand in this chapter.

To get a handle to a report use function ChooseReport(..) ...
0
 

Author Comment

by:Bruce-Dev
ID: 35069767
Thommy,

I have downloaded this chapter before and printed and studied it.  This still does not help me.  I will review again, as you say, it should be easy.  I have called DLL's before from within programs and never had this amount of issues.

I will review the other links you sent although I am using the rrdecl32.pas file in my program (one simple form and a button to print)

Best regards,

Bruce

0
 
LVL 24

Assisted Solution

by:jimyX
jimyX earned 100 total points
ID: 35071935
I suspect you have a memory/pointer (PInteger, PLongInt, Pchar, PAnsiChar) issue make sure you are using them correctly (assuming the dll and the functions are correctly written/handled).

http://rvelthuis.de/articles/articles-pointers.html
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35072467
Ok, Bruce.

Just wanted to be sure, that you are experienced in using DLLs with Delphi...

0
 

Author Comment

by:Bruce-Dev
ID: 35072497
Thommy,

No - never used DLL's in Delphi and only used Delphi several years ago so a bit rusty.

Best regards,

Bruce
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35072862
Try This...

...
RepHandle:= chooseReport(AppName,LibName,LSize,Rep,SizeOf(Rep));
...
0
 
LVL 19

Expert Comment

by:Thommy
ID: 35072883
If you have problems with the path, try it with double backslashes...

Rep := 'c:\\dev\\edm2000\\rr\\wards.rrw';
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:Bruce-Dev
ID: 35082011
Update: Tied the last two suggestions from Thommy but did not resolve issue.  I am currently working through the various links to determine where I have gone wrong.

I will let you know if I resolve this today.

Best regards,

Bruce
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35082021
Did you check the pointer variables? They can cause the AV errors.
0
 

Author Comment

by:Bruce-Dev
ID: 35082059
JimyX,

I am doing this now - let you know how this works.

Best regards,

Bruce
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35082113
Did you read my above post #35071935?
0
 

Author Comment

by:Bruce-Dev
ID: 35082253
I have been reading this last night and this morning.
0
 
LVL 24

Expert Comment

by:jimyX
ID: 35082313
OK did you find out whether the functions are handling those pointers properly? If you do not need pointers just change (work around) PInteger to Integer for instance and PChar to String (unless it's required that way).
0
 

Author Comment

by:Bruce-Dev
ID: 35082348
jimyX,

I am using the variable types set in the rrded32.pas file that is provided with R&R.  As you can see from the authors comment, even they were not sure of the pointer types!

Best regards,

Bruce

PS: After trying various combinations I have found that the following line give the error:

getErrorInfo(RepHandle,lpszMsg,mSize,lpiCode);

However, even without this line the report fails to run.

{Issues:
   We changed all Booleans to LongBools.  Do we need to do likewise for Integers?
   How do you say "pointer to LongBool"?  (PLongBool?)
   Adding stdcall to all prototypes makes this stuff work, but why?  (C header declares
      all functions as "WINAPI PASCAL".)
   
}

unit RRDecl32;

interface

uses WinTypes;


function choosePrinter(HReport:Integer; Printer:PChar; PrSize:Integer; Port:PChar; PoSize:Integer): LongBool; far; stdcall;
function chooseReport(AppName:PChar; LibName:PChar; LSize:Integer; Rep:PChar; RSize:Integer): Integer; far; stdcall;
function chooseTable(HReport:Integer; Table:PChar; TSize:Integer): LongBool; far; stdcall;
function endReport(HReport: Integer): LongBool; far; stdcall;
function endRuntimeInstance(): LongBool; far; stdcall;
function execRuntime(HReport:Integer; bWait:LongBool; FsCmdShow: Integer; pCode: PInteger; pPageCount: PLongInt; EMsg:PChar; Emsgsize: Integer): LongBool; far; stdcall;
function getAPIVersion(APIVersion: PLongInt): LongBool; far; stdcall;
function getBeginPage(HReport: Integer; pPage: PLongInt): LongBool; far; stdcall;
function getCopies(HReport: Integer; pCopies: PInteger): LongBool; far; stdcall;
function getDBContainer(HReport:Integer; pPath:PChar; Size:Integer): LongBool; far; stdcall;
function getDisplayErrors(HReport:Integer; pDispErr: PBool): LongBool; far; stdcall;
function getDisplayStatus(HReport:Integer; pDispStatus:PBool): LongBool; far; stdcall;
function getEndPage(HReport:Integer; pPage: PLongInt): LongBool; far; stdcall;
function getErrorInfo(HReport:Integer; Msg:PChar; Size:Integer; pCode:PInteger): LongBool; far; stdcall;
function getExportDest(HReport:Integer; Dest: PChar): LongBool; far; stdcall;
function getFilter(HReport:Integer; Filter:PChar; Size:Integer): LongBool; far; stdcall;
function getFilterUsage(HReport:Integer; Usage: PChar): LongBool; far; stdcall;
function getFirstFieldName(HReport:Integer; FieldName:PChar; Size:Integer): LongBool; far; stdcall;
function getFirstFilteredFieldName(HReport:Integer; FieldName:PChar; Size:Integer; Filter:Integer): LongBool; far; stdcall;
function getFirstGroupField(HReport:Integer; GroupFldName:PChar; Size:Integer): LongBool; far; stdcall;
function getFirstRelationInfo(HReport:Integer; FilePath:PChar; FSize:Integer; IndexPath:PChar; ISize:Integer; Tag:PChar; TSize:integer; Alias:PChar; ASize:integer): LongBool; far; stdcall;
function getFirstSortField(HReport:Integer; SortFieldName:PChar; Size:Integer): LongBool; far; stdcall;
function getFirstUserParam(HReport:Integer; ParmName:PChar; NSize:Integer; PValue:PChar; VSize:Integer): LongBool; far; stdcall;
function getHighScope(HReport:Integer; Scope:PChar; Size:Integer): LongBool; far; stdcall;
function getLibrary(HReport:Integer; LibName:PChar; Size:Integer): LongBool; far; stdcall;
function getLowScope(HReport:Integer; Scope:PChar; Size:Integer): LongBool; far; stdcall;
function getMasterIndexInfo(HReport:Integer; Path:PChar; Size:Integer; pType:PChar; Tag:PChar; TSize:Integer): LongBool; far; stdcall;
function getMasterTableName(HReport:Integer; Path:PChar; Size:Integer): LongBool; far; stdcall;
function getMemoName(HReport:Integer; MemoNamePath:PChar; Size:Integer): LongBool; far; stdcall;
function getNewReportHandle(AppName:PChar): Integer; far; stdcall;
function getNextFieldName(HReport:Integer; FieldName:PChar; Size:Integer): LongBool; far; stdcall;
function getNextFilteredFieldName(HReport:Integer; FieldName:PChar; Size:Integer; Filter:Integer): LongBool; far; stdcall;
function getNextGroupField(HReport:Integer; GroupFieldName:PChar; Size:Integer): LongBool; far; stdcall;
function getNextRelationInfo(HReport:Integer; FilePath:PChar; FSize:Integer; IndexPath:PChar; ISize:Integer; Tag:PChar; TSize:integer; Alias:PChar; ASize:integer): LongBool; far; stdcall;
function getNextSortField(HReport:Integer; SortFieldName:PChar; Size:Integer): LongBool; far; stdcall;
function getNextUserParam(HReport:Integer; ParmName:PChar; NSize:Integer; Value:PChar; VSize:Integer): LongBool; far; stdcall;
function getOutputDest(HReport:Integer; Dest:PChar; Size:Integer): LongBool; far; stdcall;
function getOutputFile(HReport:Integer; OutFilePath:PChar; Size: Integer): LongBool; far; stdcall;
function getPreventEscape(HReport:Integer; pbNoEsc:PBool): LongBool; far; stdcall;
function getPrinter(HReport:Integer; Printer: PChar; Size: Integer): LongBool; far; stdcall;
function getPrinterPort(HReport:Integer; Port:PChar; Size:Integer): LongBool; far; stdcall;
function getReportPick(HReport:Integer; RepPick:PChar): LongBool; far; stdcall;
function getRuntimeRecord(AppName:PChar; Filename:PChar): Integer; far; stdcall;
function getScopeUsage(HReport:Integer; ScopeUse:PChar): LongBool; far; stdcall;
function getStatusEveryPage(HReport:Integer; pbEvery:PBool): LongBool; far; stdcall;
function getTestPattern(HReport:Integer; pbTest:PBool): LongBool; far; stdcall;
function getWinTitle(HReport:Integer; Title:PChar; Size:Integer): LongBool; far; stdcall;
//function initRuntimeInstance(): LongBool; far; stdcall;
function resetErrorInfo(HReport:Integer): LongBool; far; stdcall;
function setBeginPage(HReport: Integer; Page: LongInt): LongBool; far; stdcall;
function setCopies(HReport: Integer; Copies: Integer): LongBool; far; stdcall;
function setDataDir(HReport:Integer; Directory:PChar): LongBool; far; stdcall;
function setDBContainer(HReport:Integer; Path:PChar): LongBool; far; stdcall;
function setDisplayErrors(HReport:Integer; bDispErr: LongBool): LongBool; far; stdcall;
function setDisplayStatus(HReport:Integer; bDispStatus: LongBool): LongBool; far; stdcall;
function setEndPage(HReport: Integer; Page: LongInt): LongBool; far; stdcall;
function setExportDest(HReport:Integer; ExpDest: char ): LongBool; far; stdcall;
function setFilter(HReport:Integer; Filter: PChar): LongBool; far; stdcall;
function setFilterUsage(HReport:Integer; Usage:Char): LongBool; far; stdcall;
function setGroupField(HReport:Integer; GroupFieldName:PChar; GroupFieldNum:Integer): LongBool; far; stdcall;
function setHighScope(HReport:Integer; Scope:PChar): LongBool; far; stdcall;
function setImageDir(HReport:Integer; Dir:PChar): LongBool; far; stdcall;
function setIndexExtension(HReport:Integer; ExtNumber:Integer): LongBool; far; stdcall;
function setLibrary(HReport:Integer; LibName:PChar): LongBool; far; stdcall;
function setLibraryDir(HReport:Integer; DirName:PChar): LongBool; far; stdcall;
function setLowScope(HReport:Integer; Scope:PChar): LongBool; far; stdcall;
function setMasterIndexInfo(HReport:Integer; Path:PChar; pType:Char; Tag:PChar): LongBool; far; stdcall;
function setMasterTableName(HReport:Integer; MastFileName:PChar): LongBool; far; stdcall;
function setMemoName(HReport:Integer; MemoPath:PChar): LongBool; far; stdcall;
function setOutputDest(HReport:Integer; Dest:PChar): LongBool; far; stdcall;
function setOutputFile(HReport:Integer; Filename:PChar): LongBool; far; stdcall;
function setPreventEscape(HReport:Integer; bNoEsc:LongBool): LongBool; far; stdcall;
function setPrinter(HReport:Integer; Printer:PChar): LongBool; far; stdcall;
function setPrinterPort(HReport:Integer; Port:PChar): LongBool; far; stdcall;
function setRelationInfo(HReport:Integer; Path:PChar; IndexPath:PChar; Tag:PChar; Alias:PChar; AliasNum:Integer): LongBool; far; stdcall;
function setReportPick(HReport:Integer; RepPick:Char): LongBool; far; stdcall;
function setScopeUsage(HReport:Integer; ScopeFlag:Char): LongBool; far; stdcall;
function setSortField(HReport:Integer; SortFieldName:PChar; SortNum:Integer): LongBool; far; stdcall;
function setStatusEveryPage(HReport:Integer; bValue:LongBool): LongBool; far; stdcall;
function setStatusFileName(HReport:Integer; Filename:PChar): LongBool; far; stdcall;
function setSuppressTitle(HReport:Integer; bValue:LongBool): LongBool; far; stdcall;
function setTestPattern(HReport:Integer; bValue:LongBool): LongBool; far; stdcall;
function setUserParam(HReport:Integer; ParamName:PChar; Value:PChar): LongBool; far; stdcall;
function setWinBorderStyle(HReport:Integer; Style:Integer): LongBool; far; stdcall;
function setWinControlBox(HReport:Integer; ControlBox:LongBool): LongBool; far; stdcall;
function setWinHeight(HReport:Integer; Height:Integer): LongBool; far; stdcall;
function setWinLeft(HReport:Integer; Left:Integer): LongBool; far; stdcall;
function setWinMaxButton(HReport:Integer; bAllow:LongBool): LongBool; far; stdcall;
function setWinMinButton(HReport:Integer; bAllow:LongBool): LongBool; far; stdcall;
function setWinParentHandle(HReport:Integer; Parent:Integer): LongBool; far; stdcall;
function setWinTitle(HReport:Integer; WinTitle:PChar): LongBool; far; stdcall;
function setWinTop(HReport:Integer; WinTop:Integer): LongBool; far; stdcall;
function setWinWidth(HReport:Integer; WinWidth:Integer): LongBool; far; stdcall;
function setWriteAllow(HReport:Integer; bAllow:LongBool): LongBool; far; stdcall;
function setXBaseEditor(HReport:Integer; bXBase:LongBool): LongBool; far; stdcall;
function tabChooseTable(table:PChar; tSize:Integer): Integer; far; stdcall;
function tabFreeHandle(hTable:Integer): LongBool; far; stdcall;
function tabGetErrorInfo(hReport:Integer; Msg:PChar; size:Integer; Code:PInteger): LongBool; far; stdcall;
//function tabGetFirstFieldInfo(hTable:Integer; FieldName:PChar; iSize:Integer; Type:PChar; Lgt:PInteger; DecPl:PInteger): LongBool; far; stdcall;
//function tabGetNextFieldInfo(hTable:Integer; FieldName:PChar; iSize:Integer; Type:PChar; Lgt:PInteger; DecPl:PInteger): LongBool; far; stdcall;
function tabResetErrorInfo(hReport:Integer): LongBool; far; stdcall;
function writeRuntimeRecord(HReport:Integer; RecordFile:PChar): LongBool; far; stdcall;

implementation

function ChoosePrinter; external 'RRRPT32.DLL' name 'choosePrinter';
function ChooseReport; external 'RRRPT32.DLL' name 'chooseReport';
function ChooseTable; external 'RRRPT32.DLL' name 'chooseTable';
function EndReport; external 'RRRPT32.DLL' name 'endReport';
function EndRuntimeInstance; external 'RRRPT32.DLL' name 'endRuntimeInstance';
function ExecRuntime; external 'RRRPT32.DLL' name 'execRuntime';
function GetAPIVersion; external 'RRRPT32.DLL' name 'getAPIVersion';
function GetBeginPage; external 'RRRPT32.DLL' name 'getBeginPage';
function GetCopies; external 'RRRPT32.DLL' name 'getCopies';
function GetDBContainer;external 'RRRPT32.DLL' name 'getDBContainer';
function GetDisplayErrors; external 'RRRPT32.DLL' name 'getDisplayErrors';
function GetDisplayStatus; external 'RRRPT32.DLL' name 'getDisplayStatus';
function GetEndPage; external 'RRRPT32.DLL' name  'getEndPage';
function GetErrorInfo; external 'RRRPT32.DLL' name 'getErrorInfo';
function GetExportDest; external 'RRRPT32.DLL' name 'getExportDest';
function GetFilter; external 'RRRPT32.DLL' name 'getFilter';
function GetFilterUsage; external 'RRRPT32.DLL' name 'getFilterUsage';
function GetFirstFieldName; external 'RRRPT32.DLL' name 'getFirstFieldName';
function GetFirstFilteredFieldName; external 'RRRPT32.DLL' name 'getFirstFilteredFieldName';
function GetFirstGroupField; external 'RRRPT32.DLL' name 'getFirstGroupField';
function GetFirstRelationInfo; external 'RRRPT32.DLL' name 'getFirstRelationInfo';
function GetFirstSortField; external 'RRRPT32.DLL' name 'getFirstSortField';
function GetFirstUserParam; external 'RRRPT32.DLL' name 'getFirstUserParam';
function GetHighScope; external 'RRRPT32.DLL' name 'getHighScope';
function GetLibrary; external 'RRRPT32.DLL' name 'getLibrary';
function GetLowScope; external 'RRRPT32.DLL' name 'getLowScope';
function GetMasterIndexInfo; external 'RRRPT32.DLL' name 'getMasterIndexInfo';
function GetMasterTableName; external 'RRRPT32.DLL' name 'getMasterTableName';
function GetMemoName; external 'RRRPT32.DLL' name 'getMemoName';
function GetNewReportHandle; external 'RRRPT32.DLL' name 'getNewReportHandle';
function GetNextFieldName; external 'RRRPT32.DLL' name 'getNextFieldName';
function GetNextFilteredFieldName; external 'RRRPT32.DLL' name 'getNextFilteredFieldName';
function GetNextGroupField; external 'RRRPT32.DLL' name 'getNextGroupField';
function GetNextRelationInfo; external 'RRRPT32.DLL' name 'getNextRelationInfo';
function GetNextSortField; external 'RRRPT32.DLL' name 'getNextSortField';
function GetNextUserParam; external 'RRRPT32.DLL' name 'getNextUserParam';
function GetOutputDest; external 'RRRPT32.DLL' name 'getOutputDest';
function GetOutputFile; external 'RRRPT32.DLL' name 'getOutputFile';
function GetPreventEscape; external 'RRRPT32.DLL' name 'getPreventEscape';
function GetPrinter; external 'RRRPT32.DLL' name 'getPrinter';
function GetPrinterPort; external 'RRRPT32.DLL'name 'getPrinterPort';
function GetReportPick; external 'RRRPT32.DLL' name 'getReportPick';
function GetRuntimeRecord; external 'RRRPT32.DLL' name 'getRunTimeRecord';
function GetScopeUsage; external 'RRRPT32.DLL' name  'getScopeUsage';
function GetStatusEveryPage; external 'RRRPT32.DLL' name 'getStatusEveryPage';
function GetTestPattern; external 'RRRPT32.DLL' name 'getTestPattern';
function GetWinTitle; external 'RRRPT32.DLL' name 'getWinTitle';
function ResetErrorInfo; external 'RRRPT32.DLL' name 'resetErrorInfo';
function SetBeginPage; external 'RRRPT32.DLL' name 'setBeginPage';
function SetCopies; external 'RRRPT32.DLL' name 'setCopies';
function SetDataDir; external 'RRRPT32.DLL' name 'setDataDir';
function SetDBContainer; external 'RRRPT32.DLL' name 'setDBContainer';
function SetDisplayErrors; external 'RRRPT32.DLL' name 'setDisplayErrors';
function SetDisplayStatus; external 'RRRPT32.DLL' name 'setDisplayStatus';
function SetEndPage; external 'RRRPT32.DLL' name 'setEndPage';
function SetExportDest; external 'RRRPT32.DLL' name 'setExportDest';
function SetFilter; external 'RRRPT32.DLL' name 'setFilter';
function SetFilterUsage; external 'RRRPT32.DLL' name 'setFilterUsage';
function SetGroupField; external 'RRRPT32.DLL' name 'setGroupField';
function SetHighScope; external 'RRRPT32.DLL' name 'setHighScope';
function SetImageDir; external 'RRRPT32.DLL' name 'setImageDir';
function SetIndexExtension; external 'RRRPT32.DLL' name 'setIndexExtension';
function SetLibrary; external 'RRRPT32.DLL' name 'setLibrary';
function SetLibraryDir; external 'RRRPT32.DLL' name 'setLibraryDir';
function SetLowScope; external 'RRRPT32.DLL' name 'setLowScope';
function SetMasterIndexInfo; external 'RRRPT32.DLL' name 'setMasterIndexInfo';
function SetMasterTableName; external 'RRRPT32.DLL' name 'setMasterTableName';
function SetMemoName; external 'RRRPT32.DLL' name 'setMemoName';
function SetOutputDest; external 'RRRPT32.DLL' name 'setOutputDest';
function SetOutputFile; external 'RRRPT32.DLL' name 'setOutputFile';
function SetPreventEscape; external 'RRRPT32.DLL' name  'setPreventEscape';
function SetPrinter; external 'RRRPT32.DLL' name 'setPrinter';
function SetPrinterPort; external 'RRRPT32.DLL' name 'setPrinterPort';
function SetRelationInfo; external 'RRRPT32.DLL'name 'setRelationInfo';
function SetReportPick; external 'RRRPT32.DLL' name 'setReportPick';
function SetScopeUsage; external 'RRRPT32.DLL' name 'setScopeUsage';
function SetSortField; external 'RRRPT32.DLL' name 'setSortField';
function SetStatusEveryPage; external 'RRRPT32.DLL' name 'setStatusEveryPage';
function SetStatusFileName; external 'RRRPT32.DLL' name 'setStatusFileName';
function SetSuppressTitle; external 'RRRPT32.DLL' name 'setSuppressTitle';
function SetTestPattern; external 'RRRPT32.DLL' name 'setTestPattern';
function SetUserParam; external 'RRRPT32.DLL' name 'setUserParam';
function SetWinBorderStyle; external 'RRRPT32.DLL' name 'setWinBorderStyle';
function SetWinControlBox; external 'RRRPT32.DLL' name 'setWinControlBox';
function SetWinHeight; external 'RRRPT32.DLL' name 'setWinHeight';
function SetWinLeft; external 'RRRPT32.DLL' name 'setWinLeft';
function SetWinMaxButton; external 'RRRPT32.DLL' name 'setWinMaxButton';
function SetWinMinButton; external 'RRRPT32.DLL' name 'setWinMinButton';
function SetWinParentHandle; external 'RRRPT32.DLL' name 'setWinParentHandle';
function SetWinTitle; external 'RRRPT32.DLL' name 'setWinTitle';
function SetWinTop; external 'RRRPT32.DLL' name 'setWinTop';
function SetWinWidth; external 'RRRPT32.DLL' name 'setWinWidth';
function SetWriteAllow; external 'RRRPT32.DLL' name 'setWriteAllow';
function SetXBaseEditor; external 'RRRPT32.DLL' name 'setXBaseEditor';
function TabChooseTable; external 'RRRPT32.DLL' name 'tabChooseTable';
function TabFreeHandle; external 'RRRPT32.DLL' name 'tabFreeHandle';
function TabGetErrorInfo; external 'RRRPT32.DLL' name 'tabGetErrorInfo';
//function TabGetFirstFieldInfo; external 'RRRPT32.DLL' name 'tabGetFirstFieldInfo';
//function TabGetNextFieldInfo; external 'RRRPT32.DLL' name 'tabGetNextFieldInfo';
function TabResetErrorInfo; external 'RRRPT32.DLL' name 'tabResetErrorInfo';
function WriteRuntimeRecord; external 'RRRPT32.DLL' name 'writeRuntimeRecord';

end.

Open in new window

0
 

Author Comment

by:Bruce-Dev
ID: 35083679
JimyX,

I have now read Rudy's article on pointers and not sure how this will help with the use of the R&R DLL calls.  As I have no more information about the pointer types than that included in the rrdecl.pas file I am unsure how to progress this further.

Best regards,

Bruce

0
 
LVL 32

Accepted Solution

by:
ewangoya earned 400 total points
ID: 35091126
You are not initializing a lot of your variables and sending nil pointers
Try this, put a break point in your code and note the exact line that causes an error
procedure TForm1.Button3Click(Sender: TObject);
var
  RepHandle: integer;
  RtnBol: LongBool;

  bWait: Boolean;
  FsCmdShow: Integer;
  lpszEMsg: array[0..511] of char;
  lpiECode: Integer;
  lplPageCount: LongInt;

  pszAppName: PChar;
  lpszLibName: array[0..255] of char;
  lSize: Integer;
  lpszRepName: string;
  rSize: Integer;

  lpszMsg: array[0..511] of char;
  lpiCode: Integer;
  Ertn: LongBool;

begin
  FillChar(lpszLibName, SizeOf(lpszLibName), #0);
  FillChar(lpszMsg, SizeOf(lpszMsg), #0);
  FillChar(lpszEMsg, SizeOf(lpszEMsg), #0);

  lpszRepName := 'c:\\dev\\edm2000\\rr\\wards.rrw';

  bWait := true;
  FsCmdShow:= 0;
  lplPageCount := 0;
  lpiECode := 0;

  // Start R&R routine
  resetErrorInfo(0); // clears the error buffer

  RepHandle := chooseReport(nil, @lpszLibName[0], SizeOf(lpszLibName),
    PChar(lpszRepName), Length(lpszRepName));
  if RepHandle = 0 then
  begin
    // Check for errors
    getErrorInfo(RepHandle, @lpszMsg[0], SizeOf(lpszMsg), @lpiCode);
    //do something with the returned error code
    Exit;
  end;

  // Set runtime settings here...
  RtnBol := execRuntime(RepHandle, bWait, FsCmdShow, @lpiECode, @lplPageCount,
    @lpszEMsg[0], SizeOf(lpszEMsg));
  if RtnBol then
  begin
    showmessage('Report returned True');
  end
  else
  begin    
    getErrorInfo(RepHandle, @lpszMsg[0], SizeOf(lpszMsg), @lpiCode);
    showmessage('Report returned False: ' + string(lpszMsg))
  end;
end;

Open in new window

0
 

Author Closing Comment

by:Bruce-Dev
ID: 35106611
If I had more points I would give them.  I have spent weeks working on this problem.  Thank you all that have assisted with this problem.
0
 

Author Comment

by:Bruce-Dev
ID: 35106618
Ewangoya,

Sorry for the delay in replying but the site went down after I input my reply and lost my input. :-(

Your code worked well - thank you.

JimyX: Your input was also helpful and I now understand the point you made regarding the pointers in Delphi.

Thommy: You input was useful and I thank you for your quick assistance.

If I had the facility I would award you all points for the effort you have made.

I have included my final code that will permit any R&R report to be selected and run within Delphi 2007, I hope this may be of use to others.

Best regards,

Bruce

procedure TForm1.Button3Click(Sender: TObject);
var
  RepHandle: integer;
  RtnBol: LongBool;

  bWait: Boolean;
  FsCmdShow: Integer;
  lpszEMsg: array[0..511] of char;
  lpiECode: Integer;
  lplPageCount: LongInt;

  pszAppName: PChar;
  lpszLibName: array[0..255] of char;
  lSize: Integer;
  lpszRepName: string;
  rSize: Integer;

  lpszMsg: array[0..511] of char;
  lpiCode: Integer;
  Ertn: LongBool;


begin
  FillChar(lpszLibName, SizeOf(lpszLibName), #0);
  FillChar(lpszMsg, SizeOf(lpszMsg), #0);
  FillChar(lpszEMsg, SizeOf(lpszEMsg), #0);

 // lpszRepName := 'c:\\dev\\edm2000\\rr\\ward.rrw';  // Either format works fine.
 lpszRepName := 'c:\dev\edm2000\rr\ward.rrw';

  bWait := true;
  FsCmdShow:= 0;
  lplPageCount := 0;
  lpiECode := 0;

  // Start R&R routine
  resetErrorInfo(0); // clears the error buffer

  RepHandle := chooseReport(nil, @lpszLibName[0], SizeOf(lpszLibName),
    PChar(lpszRepName), Length(lpszRepName));

  setDisplayStatus (RepHandle, True); // display a status window...
  setOutputDest (RepHandle, '?');     // control output of report - ? = give the user options to select
  setPrinter (RepHandle, '?'); // Provide user option to select printer
  setLibraryDir (RepHandle, 'c:\dev\edm2000\rr\');  // set default source for reports
  setReportPick (RepHandle, 'R');  // User can select any report
  setWinBorderStyle (RepHandle, 2); // report preview is in sizable window
  setWinTitle (RepHandle, 'Integration report');  // Set window title




  // Set runtime settings here...
  RtnBol := execRuntime(RepHandle, bWait, FsCmdShow, @lpiECode, @lplPageCount,
    @lpszEMsg[0], SizeOf(lpszEMsg));

 if RepHandle = 0 then
  begin
    // Check for errors
    getErrorInfo(RepHandle, @lpszMsg[0], SizeOf(lpszMsg), @lpiCode);
    //do something with the returned error code
     showmessage('Report encountered an error: ' + string(lpszMsg) + ', lpicode: ' + string(@lpiCode) );
    Exit;
  end
  else
      begin
    showmessage('Report ran successfully');
   end
  end;

Open in new window

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi OLE Error 8 84
Delphi XE10 Round Image 2 48
Create a path if not exists 7 45
Delphi: Connect to running MS Outlook 4 28
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now