Questions tagged [global-variables]

Global variables are variables that are accessible from all elements of a software component.

Global variables are variables that are accessible from all elements of a software component.

Global variables are used to share information between elements of a component and to store a part of the component's state. They therfore:

  • create a hidden coupling between all the elements that use them;
  • are a source of accidental bugs and inconsistencies, when changes and side-effects are not sufficiently controlled.
8810 questions
2
votes
2 answers

Calling an object from module function

I have the following problem: In my main I have some objcts (currently the button and later the car). I want to acces their functions from functions in a module. first file (main): from tkinter import * from tkinter import ttk from PIL import Image,…
gnicki
  • 53
  • 7
2
votes
2 answers

How can I express interaction via global variable in sequence diagram

I want to draw a sequence diagram for following example. I know that I can use message line when there is a function call interaction for data exchange. But in this case, read function interface is not defined since the target variable is defined as…
user1808808
  • 33
  • 1
  • 5
2
votes
2 answers

Django : make a variable persistent

Basically I want to make a variable persitent in Django and I don't know how. To be more precise, I want a user to choose a specific project when he logs in the site (via a ChoiceField for example). Then, for as long as he does not select another…
2
votes
2 answers

XSLT Parsing multiple nested children with tag id help

I have the following xml that I need parsed into name/value pairs using XSLT. No matter what I try, I cannot get it right. I know you cannot have a global "counter" to keep track of the batches, but I have tried recursive templates, calling a java…
2
votes
1 answer

Why global variable in swift file doesn't look like initialized correctly at debugging?

my code is very simple, in ContentView.swift file: import SwiftUI struct NavTab { let name: String } let tab0 = NavTab(name: "tab0") struct ContentView: View { var body: some View { Text("Hello, world!") .onAppear { …
hopy
  • 559
  • 3
  • 18
2
votes
1 answer

How to declare a global const variable and initialize it with a function in C?

I would like to declare a constant global variable and initialize it with a function. The problem is, I can't use my function to initialize it because a function call is not a compiler-time constant, but I also can't split the declaration and the…
Hobbes
  • 177
  • 8
2
votes
1 answer

No access to static (non-primitive) members in constructor of global variable in C++

The following code works fine when using e.g. int instead of std::string, std::map etc. I have a global variable that needs an entry of the static member when using the default constructor, but this string is empty here. The variable "test" does not…
Close Call
  • 653
  • 1
  • 6
  • 18
2
votes
1 answer

Quasar 2 Vue 3 how to access app.config.globalProperties through "this" object in .vue files?

I am using Quasar 2 Vue 3. Currently I need to import app from "../boot/firebaseConfig"; in every .vue files and access global variables using app.config.globalProperties. syntax. Is there anyway to shorten this to just using this.?
Kok How Teh
  • 3,298
  • 6
  • 47
  • 85
2
votes
2 answers

Best way to store information used by entire program?

Say I have some program-wide information, like the root directory of the program or the language selected, that I would like the user to be able to change. How should I best go about storing this information in a form easily accessible at any time…
wrongusername
  • 18,564
  • 40
  • 130
  • 214
2
votes
2 answers

Global Variables for Javascript (Acrobat Reader)

I have a PDF form and I'm trying to declare a global variable in the Document-level Javascript editor... I'm using global.myVariable = "0"; and then on a field in the form, I'm running the code: if(myVariable == "0"){ app.alert("Hello!"); …
Lena
  • 21
  • 1
  • 2
2
votes
1 answer

How to assign new values to global variable from inside a function

I want a function to assign a new value to a global variable: value = "" function edit_value(v::String) value = v end However, it does not assign the global value the new value. Julia creates a new local variable value inside the function. How…
pooooky
  • 490
  • 2
  • 12
2
votes
1 answer

How to access the global window variable if there's a local window variable?

Just out of curiosity, how would you access the global window object inside a function with this signature: function bla(window){ // How to access the global 'window' object here? Because 'window' is now local. }
stackzebra
  • 450
  • 1
  • 6
  • 13
2
votes
4 answers

Can we really restrict the scope of a global variable using Static?

I have read somewhere that we can restrict the scope of global variable to a file only by using static keyword before variable name. But, when i tried it practically it comes out to be false: //1st file - file1.c //2nd file -…
Amit Singh Tomar
  • 8,380
  • 27
  • 120
  • 199
2
votes
3 answers

Make available a variable in multiple forms in compact framework

I'm doing an application for a Windows CE 5.0 device that asks for the username in the first form (when the application is launched), and then I get the userId from a database table. After that a menu form appears which receives the userId, and I…
rfc1484
  • 9,441
  • 16
  • 72
  • 123
2
votes
1 answer

What's the optimal way to use global variables?

The fact the global variables in python are slower than local ones is pretty well known and has already been discussed in different questions in this site. However, one thing I still haven't found an answer for is, what's the best and fastest way to…
aviro
  • 184
  • 9