Codetyko,
There are several ways, all of which will require some code on your part, and there are a few caveat's to them. One of the better approaches I've found is to do the following:
Create a .DBF file called CONTROL.DBF It should have the following structure:
Fieldname Type
USERID C10
LOGINDATE D
One of the main problems with this type of control is that, if the app crashes for some reason, The value won't get reset... for that reason, I track date, and time, and then make an assumption... it's fairly reliable. I also assume here you have some type of User-ID implemented in your code, and that a user has to log on. If you do not, let me know, and I will e-mail you my security routines. I will assume that you capture the Users ID in some type of memvar, for this example, I'll call it M.USERID. The code you will add immediatly after your logon is:
IF NOT USED('CONTROL')
SELECT 0
USE CONTROL
ELSE
SELECT CONTROL
ENDIF
*
* The code below is to reset the file, basically daily.
* This will clear the file, in the even that someone
* exited the application "Ungracefully". Usually, due
* to the application crashing. Since the number of
* records is basically what we are monitoring, ZAPPING
* the table, basically the first time someone logs in
* on a daily basis, resets it's total count. It's not
* fool prof, but it works fairly well. A good hacker
* could fool it...
SELECT CONTROL
GO BOTT
IF DATE() # CONTROL.LOGINDATE
SELECT CONTROL
USE CONTROL EXCLUSIVE
ZAP
ENDIF
*
IF RECCOUNT('CONTROL') >= 5
WAIT 'Maximum Number Of Users Already Logged In. Please Try Again Later.' WINDOW TIMEOUT 5
CLEAR READ ALL
QUIT
ELSE
SELECT CONTROL
APPEND BLANK
REPLACE USERID WITH M.USERID;
LOGINDATE WITH DATE()
ENDIF
*
Note that, as an alternative to the code in the ELSE clause above, you can do this instead if you also want to ensure that no single user is logged in more than once. (Note that I use a LOCATE here for simplicity, since this file will NEVER be very large, and would run fast on even the SLOWEST of machines... I don't normally advocate the use of LOCATE, but in this case it is very effective.)
ELSE
SELECT CONTROL
LOCATE ALLTRIM(CONTROL.USERID) = (M.USERID)
IF FOUND()
WAIT 'User already logged on. Can not log-on more than once.' WINDOW TIMEOUT 5
CLEAR READ ALL
QUIT
ELSE
SELECT CONTROL
APPEND BLANK
REPLACE USERID WITH M.USERID;
LOGINDATE WITH DATE()
ENDIF
Now, the only other thing you will need to do, is at the point in time that your user exits the application, (Like, on a Quit or Exit, whatever you use...) add this code:
IF NOT USED('CONTROL')
SELECT 0
USE CONTROL EXCL
ELSE
SELECT CONTROL
ENDIF
*
LOCATE FOR M.USERID = CONTROL.USERID
IF FOUND() && Don't know why you wouldn't, but it's
&& a good code habit...
DELETE
ENDIF
*
PACK
.
.
.
<EXIT APPLICATION CODE GOES HERE...>
Hope this helps... it's a little klugy, but with some work, you could easily improve upon it.
Please let me know if this helps, or if you need additional details, or explanation.
Cheers,
-Scott