Gil,

Here is an example of dynamically requiring a package using .contex
which we use in the test framework.  It allows us to trap a syntax
error in the package within the entry code.

  signal on syntax name packageErr
  .context~package~loadPackage('INVOCATIONTester.cls')

  -- go do stuff

packageErr:
  err = .ExceptionData~new(timeStamp(), s, .ExceptionData~TRAP)
  err~setLine(sigl)
  err~conditionObject = condition('O')
  err~msg = "Failed to load the external API package needed for this
test group."

  if group~isAutomatedTest then return err

  err~print("Test group exception", .false)
return .ooTestResult~new(5)~~addException(err)

::requires xxx  -- This is the first directive in the file

This is one area that I think could turn out to be very useful.  I
probably don't explain it well above.  But take this simpler example.
Say you have a program, myApp.rex with a requires in it.

/* myApp.rex */

 -- do work

::requires "myClasses.cls"  -- This is the first directive.

Normally if you run your program and there is a syntax error in
myClasses.cls, or the myClasses.cls file is not there, you can not
trap the error in the area of 'do work' because the error happens
before your 'do work' executes.

But, by using loadPackage() you can set up your do work code to trap
an unexpected error.

You could do a similar thing and execute some code that figures out
*which* package you want to require and take out the ::requires
directive altogether.

/* myProgram.rex */

  if xx or y then do
    .context~package~loadPackage('Geometry.frm')
  end
  else do
    .context~package~loadPackage('Calculus.frm')
  end

--
Mark Miesfeld

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensign option that enables unlimited
royalty-free distribution of the report engine for externally facing 
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Oorexx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/oorexx-devel

Reply via email to