3

Is it possible to call global methods from within a class where they are obscured by member functions of the same name?

I know in C++ you have the following syntax:

int var = 0;

void temp() {
    int var = 2;
    ::var = var;
} //Global var is set to 2

2 Answers 2

13

Yes you can by using the name of the unit instead of ::

Like:

unit1.var := 2;

See for more details: http://delphi.about.com/od/beginners/l/aa060899.htm

Sign up to request clarification or add additional context in comments.

1 Comment

This is why I take issue with the use of the term "Global" in Delphi/Pascal. i.e. not Global variables, but Unit variables. If correct terminology were used then the answers to such questions would be more obvious. i.e. not "how do I refer to a global variable?", but "How do I refer to a unit variable?". The fact that "Uses" brings Unit symbols into scope is not sufficient reason to misuse the meaning of "Global" in a language that technically has no such concept (and the fact that the official help/documentation mis-uses the term too is no excuse either).
6

You can try

UnitName.VarName := 2

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.