Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make sure that the right function being called?

Status
Not open for further replies.

pctest

Programmer
Apr 12, 2004
89
US
function X exists in dummy1.prg.
function X exists in dummy2.prg.

dummy1.prg is built into test1.exe and dummy2.prg is built into test2.exe. test1.exe can call test2.exe. How can I make sure that when test1.exe calls test2.exe and test2.exe is using function X of dummy2.prg not the function X of dummy1.prg.

For example, in test2.exe, a form TESTFORM has this coding:

do X

If test2.exe is called from test1.exe, I want to make sure that TESTFORM will use the X of dummy2.prg.

Note: The "do X" coding cannot be changed since the source code for TESTFORM is not available.


Thank you for any suggestion.



 
why not store all procedures/functions in one .PRG and SET PROCEDURE in your main .prg?

anyways, maybe you could try
Code:
[COLOR=blue][b]DO <func/proc> IN <progfile>[/b][/color]

hope this helps. peace! [peace]

kilroy [trooper]
philippines

"Illegitimis non carborundum!"
 
VFP always uses the last procedure/function that it finds defined. This is evident in the following exmaple that you can run in VFP:

Code:
MESSAGEBOX(MyShowFunc())

FUNCTION MyShowFunc()
	RETURN ("First One Called!")
ENDFUNC

FUNCTION MyShowFunc()
	RETURN ("Last One Called!")
ENDFUNC

So what about Set Procedure To? Well it turns out that this works in exactly the opposite fashion. Consider the following... you have a simple project that consists of 3 prg files - Main.prg, FirstShow.prg and LastShow.prg. Within Main.prg you have the following code:
Code:
SET PROCEDURE TO FirstShow.prg

SET PROCEDURE TO LastShow.prg ADDITIVE

MESSAGEBOX(MyShowFunc())
...and in both of those procedure files you have defined the function MyShowFunc() as outlined in the first example I showed. The result of running this application would be that a messagebox would appear announcing "First One Called!"

So as you can see the answer to your question is to include something such as the following in your test2.exe
Code:
SET PROCEDURE TO Dummy2.prg

SET PROCEDURE TO Dummy1.prg ADDITIVE
...as long as you set procedure to dummy2.prg first then there will be no doubt that the Function X testform is calling is from dummy2.prg

boyd.gif

 
I'm curious why you'd have two identically named functions in two separate files. I go along with torturedmind and think you should have one procedure file that contains all common functions and procedures. At a minimum, cut the function out to its own PRG file named the same as the function. That way there'd be no chance for confusion.

Steve
 
Hi Craig,

Thank you for the detail explanation. I believe my case may be little bit more complicated.

test1.exe has coding to set procedure to dummy1.prg additive and then a set procedure to test2.exe additive. From test1.exe, there is coding to call a program inside test2.exe. Since there is already set procedure to dummy1.prg and test2.exe, I guess any set procedure in test2.exe won't matter.

I want any program inside test2.exe to use the function X in dummy2.prg.

Thank you for any help.
 
As TorturedMind indicated, DO <func/proc> IN <progfile> will insure the correct method is called.

Darrell
 
Hi Darrell,

If you read my original post carefully, I already specify that the do coding cannot be changed.


Thank you.
 
pctest,

Perhaps something like this in test2.exe's main:

Code:
SET PROCEDURE TO && clear previous settings for procedure
SET PROCEDURE TO Dummy2.prg
SET PROCEDURE TO Dummy1.prg ADDITIVE

*!* do whatever the exe does here

*!* Restore previous settings for procedure just before quitting test2.exe
SET PROCEDURE TO Dummy1.prg
SET PROCEDURE TO Dummy2.prg ADDITIVE

boyd.gif

 
Craig,

My understanding is that test2.exe's main won't get executed since I'm not issuing do test2.exe but issuing do a program inside test2.exe. Is my understanding wrong?


Thank you.
 
Ok, now I'm starting to get confused. [smile] There seems to be a lack of essential information. Maybe one of the other members can help or maybe you could provide more details about the exact situation you are dealing with. What have you've tried already that didn't work? What restrictions exist and why? Which parts of this system can you modify and which parts can't be changed? Are you trying to change the behavior of a compiled application externally? Can you be a little more specific (test.exe, test2.exe, dummy.prg and dummy2.prg are a little too vague). I'm going to run the risk of sounding pedantic here... if you want something other than guesses you'll need to provide all the pertinent pieces of information.

boyd.gif

 
pctest,

From your last post, it sounds like you're running a program named test1.exe and want to call a procedure contained within test2.exe without ever having run test2.exe.
The short answer is you can't.

That's kind of like saying you want to read pages 3-10 of a book without opening the book.

Somehow, test2.exe has to be running, preferrably instantiated from test1.exe so it can be visible to it, or at least to Windows.
Once the app is compiled into an executable, any reference to the .prgs contained within are only seen by the executable as compiled codes.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
Dave and Craig,

I hope this will be more clear.

test1.exe has the following coding:

set procedure to test2.exe (my understanding this will put test2.exe in memory)
set procedure to dummy1 (function x is defined in dummy1)

Somewhere in test1.exe, I have this coding:

do program_y with ....

program_y is a program in test2.exe.

Then, program_y will call some other programs or forms which will call function x. The problem is that the function x used will be the one from dummy1 even though there is function x in dummy2 which is one of the programs in test2.exe. I want any program/forms.. in test2.exe uses the function x in dummy2 instead of the one in dummy1.

I think if I use Craig's suggestion like this, it may work:

SET PROCEDURE TO all the procedures in memory except dummy1
SET PROCEDURE TO Dummy2.prg additive
SET PROCEDURE TO Dummy1.prg ADDITIVE

do program_y with ....

SET PROCEDURE TO all the procedures in memory except dummy2
SET PROCEDURE TO Dummy1.prg
SET PROCEDURE TO Dummy2.prg ADDITIVE



Thank you.

 
if you can still modify dummy1.prg (which contains a copy of function x) in test1.exe, renaming that same function to a unique name will also ensure you of what you need to accomplish.

hope this helps. peace! [peace]

kilroy [trooper]
philippines

"If the automobile had followed the same development cycle as the computer, a Rolls-Royce would today cost $100, get one million miles to the gallon, and explode once a year, killing everyone inside."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top