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

Is there a way to access form(ThisF 1

Status
Not open for further replies.

sashaDG

Programmer
Jun 20, 2022
112
BY
Is there a way to access form(ThisForm) or pass as an argument in a function in another file? When I try I get an error:this form can only be used within a method.

Im find:
"One of the following references was used outside of a method: THIS, THISFORM, or THISFORMSET.

You have used special references in a procedure, but these references can only be used within a method.

Move commands that use THIS, THISFORM, or THISFORMSET references to the appropriate methods."

Does this mean that there is no way to call from a function that is not located in the form?
 
Hi,

[pre]
* some method on form
callsomefunction(Thisform)
callsomefunction(Thisform.Controls(1))

* some function anywhere
PROCEDURE callsomefunction
LPARAM m.loObj
DEBUGOUT m.loObj.Name
ENDPROC

[/pre]

 
Hi sashaDG,

please try:

FUNCTION Test( oForm )
MESSAGEBOX( oForm.Caption )
ENDFUNC


call this function Test in the Init method of Your Form:

Test( THISFORM )


this should work :)

Regards, Stefan
 
StefanFoerner its works, but when I declare parameters I get an error "Unrecognuzed command verb
 
Sasha,

In general, THIS and THISFORM are just object references. And, like all object references, they can be stored in variables.

THISFORM is a reference to a form object. If you want to refer to that form outside of a method, then you can do something like this:

Code:
* Inside a method
oSomeForm = THISFORM
SomeFunction(oSomeForm)

You could then define SomeFunction like this:
Code:
* Outside a method
FUNCTION SomeFunction
LPARAMETERS tForm
* tForm now contains the object reference to the form.

The same applies to THIS, except in that case it references some other object, not necessarily a form.

You say you are getting an "Unrecognised command verb"" error. We can't tell you why that is unless you show us the line of code that is causing the error.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi sashaDG,

You can use the following two declartions of the function Test:


FUNCTION Test( parameter1, parameter2, parameter3, ... )
* Your code
ENDFUNC


- or


FUNCTION Test
PARAMETERS parameter1, parameter2, parameter3, ...

* Your code
ENDFUNC


- or


please post Your function declaration


Regards, Stefan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top