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!

Is there a way to disable page in my form when its run to another computer? 4

Status
Not open for further replies.

Mandy_crw

Programmer
Jul 23, 2020
578
PH
Hi experts... may i just ask...

I have designed my app to run in server and client...i have five pages in my form, i am thinking that when the form is run in client, page 5 is diasable, i want the server only that could have the ability to run with page 5 all other computers will not have page 5.... is that possible?
 
You could test the OS version on the server - assuming it is actually a server version of the OS
or, more simply, put a file on the server, which isn't on the clients and test for it's presence.
If it's there make the page visible, otherwise not.

Code:
if File(m.whereami+"Server.txt")
  thisform.pageframe.page1.visible = .t.
else
  thisform.pageframe.page1.visible = .f.
endif


m.whereami is just a variable made by taking just the path from sys(16)
** SYS(16) RETURNS THE EXECUTABLE COMPLETE WITH PATH AND EXTENSION...
m.WHEREAMI = JUSTPATH(SYS(16))


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Well, the server would know it's running in server mode, wouldn't it?

So depending on that you keep the pagecount at 5 or reduce it to 4.
In the init of the pageframe.
Code:
If NOT [highlight #FCE94F]<<something telling you're in servermode>> <-- this of course has to be replaced[/highlight]
   This.Pagecount = This.Pagecount-1
Endif

You could check the computername, for example, with GETENV("COMPUTERNAME").

If you want to ensure no user can make his client a server to get access to this page5, then you perhaps wouldn't want to rely on a configuration users could change, the name is harder to change, but may still be possible, they may also not change the actual computername but the Windows environment variable telling the name. So you could make it depend on other non-changeable attributes. It's hard these days to find one, as there are tools to change serial numbers and other things that are often used to uniquely identify a computer.

But the main act is simply to reduce the pagecount of the pageframe at init. Another possibility is RETURN .F. in the init of page5, because returning .F. in the init of any object means it rejects to be created.

Chriss

PS: I see Griff also has given you a simple idea of a file that has to exist. It's quite a good idea as that can be any not easily guessable file name. So to figure out how to get server mode would be hard for users, they'd need to decompile or at least suspect this idea and find file names embedded in the EXE. If they would be at the level of being able to decompile a VFP EXE you'd have other concerns, perhaps, than them running their client in server mode.
 
I would go with Griff's idea, that is, test for the presence of some arbitrary file. Except that I don't think Griff's code will work as is, because pages do not have a Visible property (as far as I know). So do this:

1. Create a text file. Name is, say, SERVER.TXT. It doesn't matter what is in it: it could be an empty file.

2. Place it in the root directory of the server.

3. In your program, test for the presence of the file, using FILE(). If it is present, then you know you are running on the server. So something like this:

[tt]THISFORM.MyPageFrame.PageCount = IIF(FILE("c:\server.txt"), 5, 4[/tt])

(This assumes: (i) the root of the server is [tt]c:[/tt]; and (ii) that there are no pages beyond Page 5. If these are not the case, adjust the code accordingly.)

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I mentioned that pages don't have a Visible property. But they do have an Enabled property. So an alternative approach would be like this:

[tt]THISFORM.MyPageFrame.Pages(5).Enabled = FILE("c:\server.txt")[/tt]

This has the advantage that it would work if there were more than five pages. A possible disadvantage would be that the use would see Page 5 as a greyed-out tab, although they would not be able to access it.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
I think it's best to act on the actual page that should not be shown. If at designtime you have a pagecount, that already creates page1 to pageN objects which each have their init.

If you define your form as PRG code classes, that's less helpful but still can be used to program pageframename.pagename.Init to return .T. or .F. there and that would not depend on the server page being the last of the pageframe, as my suggestion of reducing the pagecount by 1 needs it. My idea was to generalize it to the last page, but Mike is right it wouldn't need to be the page 5 or the last page in the long term development of things, when pages are added or removed, it could easily change to anything else.

That's again one advantage of not having forms PRG based but SCX based. When you start to design one page as the server page, that will stay the server page forever. You could give a page another PageOrder or name, but the page stays the page and could then only move if you cut and paste all its content to another page and you'd not do that as it does not move code of the page. So you could be pretty sure to put code in the server page init and that will never be broken or forgotten to change when the form evolves.

Chriss
 
Quite right Mike, there is an enabled, no visible.

Probably as well to delete it in the init method.

Taken from a real life example
Code:
IF MYFILE(m.WHEREAMI+"WEBSERVER.TXT")
	THISFORM.PF1.WEBFEATURES.ENABLED = .T.
ELSE
	THISFORM.PF1.WEBFEATURES.ENABLED = .F.
	THISFORM.PF1.REMOVEOBJECT("WebFeatures")
ENDIF

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
You also can do the opposite, you can design a server page as a separate object or class. And then only add it when your app is in server mode.

To add it to a pageframe you can do pafeframe.AddObject("yourpageclass"). When normally the pageframe simply doesn't have the server related page, there's nothing to remove.

This could even go as far as providing this specific class in a separate APP file and only have that on the server. You can't add it then, if the app file isn't there on clients. And do add a page from a separate app file you use the pageframe.NewObject() method, see its parameterization in the help, in comparison to the AddObject method it has parameters to specify an external app or exe file.

Chriss
 
One other possibility (and I post this with the risk of confusing the issue with too many information):

1. Hide the pageframe's tabs, by setting its Tabs property to .F.

2. Create a set of buttons to mimic the tabs. These could be a group of simple command buttons, or a button group, or an option group with the Style of each button set to 1 - Graphical.

3. Set the Caption of each button to match the name (or number) of a page in the pageframe.

4. In each button's Click, write code to activate the corresponding page: [tt]THISFORM.MyPageFrame.ActivePage = n[/tt] (where n is the corresponding page number).

5. If you now run the form, you will see that the buttons mimic the action of the tabs.

6. Finally, write code in the form's Init to hide the button for Page 5 when not running on the server: [tt]THISFORM.MyOptionGroup.Option5.Visible = FILE("c:\server.txt")[/tt]

That way, the non-server user will never see the fifth button, and so will never access Page 5 - or even be aware that it exists.

Mike





__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
There's also one method everyone should know about conditional compiling with preprocessor directives.

It needs preparation and strict usage, but if every of your PRGs and classes and forms etc. includes a general header file that can #DEFINE whether what you compile/build is client or server version. Provided such a header every other code includes has a #DEFINE SERVERMODE that is either .T. or .F. you can have code that has

Code:
#IF SERVERMODE
   code only for server mode
#ELSE
   code only for client mode
#ENDIF

The difference to a normal IF is that only one of the two branches is actually compiled and built into the EXE and that's not only usable for a server vs. client version but for anything that can be included or excluded from a build. Just like the idea of a separate page class in a separate APP file this would only include what a version of an EXE needs.

You then get two (or more) versions of EXEs from the same project, such switches are also commonly used to have feature en- or disabled.

Chriss
 
Hi Chriss Mike and Griff... Thank you so much... I've done what Griff gave and it worked just like magic...!!!! Thank you experts!!!! God bless....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top