RE: Call form inside project from from ouside project

Author: Kent Belan

Posted: 2012-06-15 at 07:35:32

Hello Christof,

Thanks so much for your several suggestions on ways this might work.

I really like the idea of using the oApp global application object to make

the call to the print_preview form.

If I understand correctly, the custom report will call a method in the oApp

object that will then call the print_preview form.

I am going to try this now, hope it works.

Thanks,

Kent

-----Original Message-----

From: profox-bounces@leafe.com [mailto:profox-bounces@leafe.com] On Behalf

Of Christof Wollenhaupt

Sent: Friday, June 15, 2012 6:48 AM

To: profox@leafe.com

Subject: Re: Call form inside project from from ouside project

>

> This works great. The problem I am having is from inside this external

> form, I want to call a generic print_preview form that is inside the

> project

>

What you've come across is application scope. The resolution of embedded

file names only works from within code that is attached to the same

application scope. Hence, the short answer to your problem is that you need

to call the form from within code of the main application. There are

multiple options:

a) Specify a parameter in your main program to allow multiple ways of

calling the application:

LPARAMETER tcCmd

DO CASE

CASE Empty(m.tcCmd)

* default behavior

CASE m.tcCmd == "preview" and PROGRAM(-1) != 1

DO FORM ReportPreview.SCX

OTHERWISE

* error message

ENDCASE

Then you can call your preview form by executing the main EXE

DO myApp.EXE WITH "preview"

b) The NEWOBJECT() function has a third parameter to specify the EXE.

Instead of running the form directly, you could use a ReportPreview class

that runs the form. When the function was introduced way back NEWOBJECT()

would cause dangling references to class libraries when those were loaded

from a different application. This might be fixed already. If you use ReFox

or similar tools, this approach will only work for the main EXE itself.

c) Pass a reference to an helper object to the form. If you create an object

in the main application and pass it to the reporting form, the helper object

still runs in the main application scope even when called from the external

form. This object would then execute the report preview.

Instead of an helper object you can use a method in the application object,

if your app has a goApp object and you don't mind the tighter coupling.

d) Rely on caching and loaded files. SET PROCEDURE and SET CLASSLIB make

files available to the instance, same with the calling stack and called

procedures. Most of those are available from external forms, too, because it

doesn't require to resolve an external file name when the code is already

loaded. However, there are subtle problems when code is unloaded or the

caching order changes. For this to work, everything must have a unique name.

If your external forms use the same classes as your main application, they

must have a different name.

e) Make the preview form an external file, too. You could copy the SCX/SCT

file into the temporary directory if it doesn't rely on any further embedded

files.

f) Convert the preview SCX into a VCX class and then use one of the options

above.

Christof

--- StripMime Report -- processed MIME parts --- multipart/alternative

text/plain (text body -- kept)

text/html

---

[excessive quoting removed by server]

_______________________________________________

Post Messages to: ProFox@leafe.com

Subscription Maintenance: http://leafe.com/mailman/listinfo/profox

OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech

Searchable Archive: http://leafe.com/archives/search/profox

This message: http://leafe.com/archives/byMID/profox/53E16F0711B94716A02FD4FDAD0B4085@LaptopW7

** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

©2012 Kent Belan