Re: Call form inside project from from ouside project

Author: Christof Wollenhaupt

Posted: 2012-06-15 at 05:47:45

>

> 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

---

_______________________________________________

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/CAL4QJhjUB6SoNmx_HZSc1cgXaNLdqPAR3OuUCin9s-SJ7hrKcw@mail.gmail.com

** 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 Christof Wollenhaupt