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

Global Parameter ?

Status
Not open for further replies.

lashwarj

IS-IT--Management
Nov 1, 2000
1,067
US
Is there a way to setup a Global Parameter. I want when my users log in for there user name and department to show up everywhere. IN the status bar and when they save records, what is the best way to pass this value
 
You could create a cusotm class that holds the information throughout the whole session.
Code:
DEFINE CLASS myGlobalClass AS CUSTOM
   username =""
   userdepartment =""
ENDDEFINE

Put the above code in your main program. And before your login screen, create an instance of the class:
oGlobal = CREATEOBJECT('myGlobalClass')

And in the valid of the password just store the information :
oGlobal.UserName = cUserName
oGlobal.userDepartement = cDepartement

And for example in the init of a form you can use:
This.Caption = alltrim(oGlobal.UserName)+Alltrim(userDepartement)
 
lashwarj

Make it a form or object property, ensure the object is visible to other objects, FI

DO FORM FORM1 NAME oForm1 LINKED

and access it by

oForm1.cUserName
oForm1.cUserDepartment

HTH

Chris [pc2]
 
in your main program you could use var's to hold this data

I have a table that holds login info. after the person is validated. I assign the rights to a public obj var

with the table selected
scatter to name ouser

ouser.password
ouser.name


Attitude is Everything
 
mgagnon, it works for the form after the login but after that I see nothing where i refrence it. I have the code in the places you have specified.
 
if i leave open the form with the username in it then it works fine global. but i want the user to log in and depending on there login use a different menu bar and forms. so in summary login screen stores the value and from there i open a screen that shows the user name and department. If they close that form the values are gone. How do i keep them
 
sounds like you did not put the code were mgagnon said.

it needs to be global, put it in the main.prg file

it sounds like you put it in a form. Attitude is Everything
 
Try using:
Public myGlobalClass
DEFINE CLASS myGlobalClass AS CUSTOM
username =""
userdepartment =""
ENDDEFINE
 
no its in my main.prg which is set as my main i know that much hahahahahahaha I might be stupid but i am not that bad, his directions were hard to mess up.
 
This is a combination of the other suggestions which I've used rather successfully.

_screen.AddProperty("User_Name","")
_screen.AddProperty("User_Department","")

Assign the values in your Login screen and they will be available everywhere you need it... it's like a public variable, but it's a property that doesn't require the creation or instantiation of a class object.

Steve

 
Here's a twist on everyones great suggestions... why not use sys(0)? It will give you global access to the logged in user and machinename. This may not work or be flexible enough in many scenarios, but I still thought I'ld throw it out.
 
keep it simple.
in the setup code

Public username,department

It will be availabe to all forms and methods. Although not a good idea to declare too many variables public.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top