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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where to put EXTERNAL ARRAY?

Status
Not open for further replies.

Mike Lewis

Programmer
Jan 10, 2003
17,516
Scotland
Just came up against this interesting problem.

I have a form that creates an array and fills it with six lines of data. The form then calls a report, which references the array. To ensure that the array stays in scope while the report is running, I have declared it as PRIVATE.

This works fine when running in the DE. But when I build the app, I see compilation errors saying that the array cannot be found.

No problem ... just add an EXTERNAL ARRAY to tell the project not to try to resolve the reference.

My question is: Where do I put the EXTERNAL ARRAY? It needs to be placed in the file that references the array, which in this case is the report. But how can you place a compile-time command in a report? Whereabout would you place it?

In fact, the report runs OK, despite the compilation errors, so it's not a big problem. It's just that I'd prefer not to see any compilation errors if possible. I know I can get round the problem by using separate variables in place of an array, but it would be nice to avoid having to do that.

Any ideas would be appriciated.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Ilyad,

I just tried putting it in the DE's Init. Didn't work. Which is perhaps not surprising -- I would only expect it to work if the array was referenced in that method, which it isn't.

Thanks anyway for the suggestion.

Auguy,

The link you posted suggests creating a dummy procedure with the same name as the array. That looks promising. I'll give it a try and report back.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
How about...

if .f.
dimension MyArray[1]
endif

in the load event of the form that runs the report?

Roger

 
Some years ago Craig Bernston advised to create a dummy procedure where the array is declared public, see thread184-911454. Also, you may find Craig Boyd's approach helpful.
 
I've adopted the solution recommended in the document that Auguy mentioned, and also in the thread that The Rambler posted. This works fine. So thanks to both of you for pointing me in the right direction.

To summarise, the solution is to create a dummy function with the same name as the array. Provided the function can be found at compile-time, the Build process won't report the unresolved reference. It doesn't affect what happens at run time; the report still finds the array OK.

Roger: Thanks also for your post, but unfortunately your suggestion won't work. I was correctly declaring the array in the form that runs the report (not in the Load, but in the method that does the REPORT FORM). The problem is that that reference wasn't visible at compile time.

Although I'm happy with the solution, next time I won't try to use an array in this way. I'll just pass separate variables. It's better than having dummy procedures lying around that might confuse some future maintenance programmer.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Mike

I use arrays a lot in reports in FPW 2.6 and always use the 'if .f. ... endif' trick in the setup snippet of the form. It works in a similar way to a dummy procedure because it never runs but is just mentioned, which is enough to satisfy the project builder. The array does have to be declared elsewhere though. The only VFP forms I have it in are converted from fpw2.6 and it's been put the load event by the converter.

Anyway, I'm glad you've got it sorted.

Roger
 
Roger,

May be the trick is to declare this array public in the IF /ENDIF block?

I saw the same trick as you suggested recently dicussed.
 
May be this will work.....

selct Form, New Property my_array[1]

refer to this everywhere as thisform.my_array, including the report, dimension thisform.my_array[6], etc.


try it.


Nasib Kalsi


 
Yes, I know for sure this works as I have several reports using thisform arrays properties.
 
Nasib,

Are you suggesting I refer to THISFORM.MyArray from an expression in a report? Surely that won't work? I haven't tried it, but I'll bet it generates "THISFORM can only be used in a method".

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
I think I will get a star from a Pros pro.
The reason being, thisformform, thatform are simply for interpreter, and are replaced by real memory address when compiled, (i think).

Yes, all expressions including report(s). I love when people bet.


Nasib Kalsi



 
Well, I just tried it, and I got exactly the error I expected ("THISFORM can only be used in a method"). Pity no-one took me up on my bet.

Come to think of it, it was the inability to use THISFORM that lead me to consider private variables in the first place.

Also, I've had the same experience with trying to use THISFORM in a menu.

Mike




__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Perhaps I had to check first if it really was an array.

Anyway, here are some of the expressions working fine in reports (in header sections):

thisform.getDetailHeading(theCat, thePart)

in detail:
thisform.oClassGroup.getGroupDescrip(theClass,theGroup)

I don't get compilation errors making an app.
 
Mike:

I am not sure where is the problem. My Veriosn Info:
9.00.0000.3504


Before posting, I tested it and without compilation error.

Would you be able to create a new project in a new directory. Where you have only one form and a command button, that will run the report where you have the thisform.MyArray[1] in the title of the report.

For sure there is something different. No matter what, I do not get the same error as you have specified ("THISFORM can only be used in a method").


Nasib
 
Ilyad and Nasim,

I'm surprised neither of you is seeing the same error, although I'm willing to admit I might be wrong. I'll do some more testing and report back.

By the way, the error I got from using THISFORM was not a compilation error; it only appeared at execution time. This is different from the issue in my original post, which was connected with the unresolved array reference.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Mike,

if THISFORM errors, have you tried _screen.activeform? Even if THISFORM works I wouldn't use it, it just seems wrong to reference the form that way, if not running inside it.

Bye, Olaf.
 
Why not? You can use local variables defined before REPORT FORM command, you can also use thisform inside the report.

I think it may be a problem if we're using NOWAIT clause and the form went out of scope already. Or something like this.

Here I'm using VFP8 now and I do not have problems referencing thisform and its methods in the report (though they were created by my colleague, I also prefer to use local or private variables instead).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top