Paradox Community
Search:

 Welcome |  What is Paradox |  Paradox Folk |  Paradox Solutions |
 Interactive Paradox |  Paradox Programming |  Internet/Intranet Development |
 Support Options |  Classified Ads |  Wish List |  Submissions 


Paradox Newsgroups  |  Paradox Web Sites  |  Paradox Book List  |  FAQs From The Corel FAQ Newsgroup  



Subject: FAQ:PdoxWin:Ways of adding Code to Reports:2002.03.06

Subject: FAQ:PdoxWin:Ways of adding Code to Reports:2002.03.06

Version 1.0 (2002.03.06)
Written by Frédéric Brouard, Mark Paukre, 
Ivica Kolar, Mike Irwin
edited by Mike Irwin

====================
0. Introduction
====================

This FAQ addresses the use of the Corel Paradox Report
Generator. It suggests the use of techniques to expand
the functionality of the reports generated. The various
techniques utilised are unsupported by Corel, and so
must be completely supported by the developer. Corel
cannot and will not provide any support or assurances that
these techniques will continue to function in the future.
However, you should be able to get them to function with
all Paradox for Windows versions from 1.0 to 10 SP2.

-------------------------------
 0.1 Legal Info and Disclaimers
-------------------------------

Paradox is a trademark of Corel.
Borland Database Engine (BDE) is a trademark of Inprise.

The information provided in this FAQ is provided "as is"
and is not warranted in any way. The information provided
in this FAQ is not endorsed or authorized by Corel or
Inprise in any shape, form, or manner.

The editors claim NO responsibility for ANY illegal
activity regarding this file, or as a result of someone
reading this file.

You encouraged to distribute this file, as long as the
copies are complete, unaltered, and are dated so that a
future reader can know how old the information is.

-------------
 0.2 Feedback
-------------

Please send feedback in a Corel Paradox newsgroup or the
news:comp.databases.Paradox newsgroup to any of the FAQ
Team mentioned in the "FAQ: FAQ FAQ" document.
Please preface the subject of your post with the string
"PDXWIN FAQ" to alert Team members to the function of
the message.

Please specify the FAQ name and section number the
comment applies to, if any.

-------------
 0.3 Attachments
-------------

These are no attachments.

-------------
 0.3 Index
-------------

1. Using calculated fields
2. Using WriteEnvironmentString from ObjectPAL Code
3. Using Embedded Scripts and Queries
4. Tricking the Report into allowing you to Edit It !
5. Manipulating Report UIObjects from ObjectPAL Code
6. Executing ObjectPAL Code
7. User Interaction with Mouse
8. Adding and Executing New Methods
9. Printing a Form
10. Imitating Line-printer Output !
11. Persistent Variables and Reports
==============================
1. Using calculated fields
==============================

You can use calculated fields in a report to place
any code that you want, so long as it returns a value.

-------------
 1.1 Example
-------------
Here is an example using fields from tables present
in the data model :

([:TABLE:APARTMNT.Loyer]+ [:TABLE:APARTMNT.Charges]+
 0.025*[:TABLE:APARTMNT.Loyer])/[:TABLE:APARTMNT.Type]
 >2200

which will return a logical value of True of False.

-------------
 1.2 Example
-------------
Here is an example using a conditionnal value

iif([:ALIAS:TABLE.Field],"Red","Green")

==============================
2. Using WriteEnvironmentString from ObjectPAL Code
==============================

You can use a value held by the Paradox Environment and
accessed with the WriteEnvironmentString() and
ReadEnvironmentString methods. This can be a simple and
efficient way of communicating information from code to
report, or, indeed, back again.

-------------
 2.1 Example
-------------
method pushButton(var eventInfo Event)
var
   reTheReport     Report
endVar
   WriteEnvironmentString("INFO", Info'value)
   reTheReport.print(":Rpts:APELCOTI")
endmethod

Code in a calculated field of the report :

ReadEnvironmentString("INFO")

==============================
3. Using Embedded Scripts and Queries
==============================

You can also start a query at the open of the report
by placing a field in the header band of the report
and by setting methods like ExecuteQBEFile (for a
query) or play (for a script).

-------------
 3.1 Example (Script)
-------------
Code in the script :

method run(var eventInfo Event)
   FormReturn(12345)
endMethod

Code in a calculated field of the report :

play("!x")

That's all that's needed and it works fine ! Obviously,
the script can be used to obtain a value in any
complicated way necessary.

-------------
 3.2 Example (Query)
-------------

Code in a calculated field of the report :

executeQBEFile(":qbe:MyQbe.qbe")

==============================
4. Tricking the Report into allowing you to Edit It !
==============================

You can also be much more specific by using a trick...

1 Add a new field in one table of your data model by
  restructururing the table with the report closed.
2 Make a reference to this field in a calculated field
  of your report.
3 Save your report
4 Destroy this field in your table.
5 Open your report.
6 An error is generated because the field reference target
  is missing and Paradox will open a complete edit window,
  in which you can place almost any ObjectPAL code that
  you wish !

==============================
5. Manipulating Report UIObjects from ObjectPAL Code
==============================

You can manipulate the Report UIObject in the code
that launches the report, like this

-------------
 5.1 Example
-------------

method pushButton(var eventInfo Event)
var
   R   Report
endVar
R.open("APELCOT2")
if Info.isBlank()
then
   R.TxtInfo.visible = false
else
   R.TxtInfo.Text = string(Info.value)
endif
R.print("APELCOTI")
endmethod

Where TxtInfo is a text UIO in the report

==============================
6. Executing ObjectPAL Code
==============================

You can execute ObjectPAL code directly from a file,
using the ExecuteString() function (see the Help).

-------------
 6.1 Example 1
-------------
This will give a simple message box to say
"Hello World" !

ExecuteString("msgInfo(\"Hello\", \"Hello  World\")")

-------------
 6.2 Example 2
-------------
Of course, you can do more complicated things.
For example, looking at the example in the Help for
using executeString(), one could do this in the ObjectPAL
code and then open the report:

var
   msgText, usesText  string
endvar

msgText = "MessageBoxA(0,\"A Message\", "+
            "\"Hello World\" , 1)"

usesText = "Uses USER32
      MessageBoxA(hwnd CLONG,
                  str1 CPTR,
                  str2 CPTR,
                  boxType CLONG) CLONG
         endUses"

writeEnvironmentString("MsgText", msgText)
writeEnvironmentString("UsesText", usesText)

and run a report that has this as the content of a
calculated field :

executeString(readEnvironmentString("MsgText"),
readEnvironmentString("UsesText"))

==============================
7. User Interaction with Mouse
==============================

Add MouseClick and make it work in a report...

-------------
 7.1 Example
-------------
Do this code in the launching report form :
var
   reMyReport   Report
   s   string
endVar
   S = "method mouseClick(var eventInfo MouseEvent)\n " +
       "msgInfo(\"ITIS\",string(today())+\"\n\"+" +
       "string(Time()))\nendmethod"
   reMyReport.load("myReport")
   reMyReport.MSG.methodSet("mouseClick",s)
   reMyReport.run()

Where MSG is a common UIO of the report.

Now close the report and save it. This event will work
but only if the report is shown in form mode...

==============================
8. Adding and Executing New Methods
==============================

With this trick, you can also place a personal method
and launch it in the calculated field.

-------------
 8.1 Example
-------------
Suppose that 'Music' is a personal method,
like this one :

;------------------------------------------------
method Music()
var
   noteQuart, octave, note        LongInt
   puissance                      Number
endVar

const
   noteDo1  = 110
   noteDo#1 = 116
   noteRe1  = 123
   noteMi1  = 130
   noteMi#1 = 138
   noteFa1  = 146
   noteFa#1 = 155
   noteSol1 = 164
   noteLa1  = 174
   noteLa#1 = 184
   noteSi1  = 195
   noteSi#1 = 207
   noteDo2  = 220
   noteDo#2 = 234

   noteRe2  = 249
   noteMi2  = 265
   noteMi#2 = 282
   noteFa2  = 300
endConst

sound(noteDo1, 200)
sound(noteFa1, 150)
sound(noteLa#1, 50)
sound(noteDo2, 100)
sound(noteRe2, 100)
sound(noteDo2,150)

sound(noteLa#1, 50)
sound(noteDo2, 100)
sound(noteRe2, 100)
sound(noteMi#2, 150)
sound(noteFa2, 50)
sound(noteDo2, 100)
sound(noteLa#1, 100)
sound(noteFa#1, 100)
sleep(1000)

noteQuart = 120

for octave from 0 to 1
   for note from 0 to 11
      sound(int(pow(2, octave + note / 12.0) * 110),
            noteQuart)
   endFor
endFor

sound(int(pow(2, 2) * 110), noteQuart)

endMethod ;(MUSIC)
;------------------------------------------------

Now, by the same way that the prior one do this :

method pushButton(var eventInfo Event)
var
   reMyReport   Report
   s   string
endVar
   S = MethodGet("Music")
   reMyReport.load("MyReport")
   reMyReport.MSG.methodSet("Music",s)
   reMyReport.run()
endmethod

Where MSG is a report field.
Save the report, and now add this code in the
calculated field called MSG:

Music()

==============================
9. Printing a Form
==============================

Do you want to print a form ?

var
   reMyReport Report
endVar
   reMyReport.open("TheForm.FSL")
   reMyReport.print()

==============================
10. Imitating Line-printer Output !
==============================

Do you want to have black or white fields ?

calculated field with this code
iif([Table.FieldLogicalType]=True," ","")

==============================
11. Persistent Variables and Reports
==============================

This technique combines the use of Environment Variables,
Calculated Fields, and the fact that a report does not 
simply "spring to life, fully-formed", but is created
sequentially.

Let us suppose that there is some calculation that is 
extremely inconvenient to program in the code that
triggers the code, and is not possible by normal summation
methods within the report. An example might be some 
calculation involving numbers that are already created 
as calculated fields

Your banded report may be considered as being in three
parts - Report Header, Data Area, and Report Footer.
The Data Area is further divisible into Before Data,
Data, and After Data when you look at the printed output.

For this technique you will need a report where the Data 
Area contains a TableFrame or a Multi-Record Object, as
there's no point in doing it otherwise.

Let us assume that we are conditioally summing values.

1.

In the report header place two calculated fields, defined
as follows:

writeEnvironmentString("MajorSum", "0")
writeEnvironmentString("MinorSum", "0")

These perform the initialisation of our storage.

2.

Within the Data Area, just below the point at which the
value to be added into our running total is displayed,
add a calculated field, as follows:

iif(
(SumField > 100.0), 
(writeEnvironmentString("MajorSum",
String(Number(readEnvironmentString("MajorSum")) +
Number(SumField)))
(writeEnvironmentString("MinorSum",
String(Number(readEnvironmentString("MinorSum")) +
Number(SumField)))
)

which adds SumField to MajorSum if it is greater than 100,
or to MinorSum otherwise. This is, of course, quite a long
piece of text for a calculated field, so one might well
want to use two fields - one to write SumField to another 
environment variable and one to invoke a script to do
the calculation shown in the immediate if above.

3.

Finally, add two more calculated fields in the Report
Footer area:

readEnvironmentString("MajorSum")
readEnvironmentString("MinorSum")

which will display your partial sums.


Paradox Community Newsgroups


 Feedback |  Paradox Day |  Who Uses Paradox |  I Use Paradox |  Downloads 


 The information provided on this Web site is not in any way sponsored or endorsed by Corel Corporation.
 Paradox is a registered trademark of Corel Corporation.


 Modified: 15 May 2003
 Terms of Use / Legal Disclaimer


 Copyright © 2001- 2003 Paradox Community. All rights reserved. 
 Company and product names are trademarks or registered trademarks of their respective companies. 
 Authors hold the copyrights to their own works. Please contact the author of any article for details.