I have no idea what you've actually done wrong because you have not posted the necessary code. However, I'll explain some things you seem to be misunderstanding about programming, and perhaps that will help. Otherwise, please update your question with relevant information from both units (we're not all psychic).
Programs execute code as a sequence of instructions. Some instructions call other instructions. And no matter what code may sit inside your first unit that sets a global variable, that variable will not change until the instruction to actually change it has executed.
So, try the following:
- Put a break-point on your line of code in unit 1 that sets the global.
- And another on the line of code that reads the global in unit 2.
- Run your program.
- You will probably find that the program stops at the unit 2 breakpoint before the unit 1 breakpoint.
- This means the instruction to change the value has not executed yet.
- (And will not execute until another line calls the appropriate instruction that will cause it to be executed.)
There are of course other possibilities (but as mentioned before, we need the code in order to debug it):
- There might be another instruction somewhere else that that clears the value you previously set.
- Although you made you variable in unit 1 global, you might find that unit 2 is looking at an entirely different value - that happens to have the same name.
- Globals are relatively simple, but if you were using objects you would also have to consider whether both references are using the same instance of your class.
- EDIT: PS: Of course, if you used
=
expecting that to set the value, you'll find it doesn't.=
is the comparison operator.:=
is the assignment operator; and when using it the result of the expression on the right will be assigned to the variable (global,local,field,argument) on the LEFT.
EDIT:
So, if you follow my earlier advice: put a breakpoint on lblWelkom.Text := Unit1.UserLogin
and another on UserLogin := EditUser.Text;
. You'll observe that you're reading the value of UserLogin
before you've assigned it. LU RD explains why it's not working, and how to fix it.