global-variables

Objective C - Static and global variable?

随声附和 提交于 2019-12-12 07:26:22
问题 In my .m file for a class named Ad , I have 3 static strings static NSString *AdStateDisabled = @"disable"; static NSString *AdStateExpired = @"expired"; static NSString *AdStateActive = @"active"; I can simply use these static variables in the current class, but i cannot call them from any other class, is there a way to make these static variables global? So for example in my viewcontroller class i can do something like. //HomeViewController.m if ([self.ad.state isEqual:Ad.AdStateDisabled])

php application global settings

梦想与她 提交于 2019-12-12 07:19:21
问题 I have read almost all question I have found on StackOverflow on this topic, but could not find a straight answer. Here is my code: Application class <?php class Application extends Settings { public function __construct($env, $cacheDir, $configFile) { self::$_env = $env; self::$_cacheDir = $cacheDir; self::$_config = $this->loadConfig($configFile) // reads configs from xml file into Config object } // other methods } ?> Settings class: <?php class Settings { protected static $_env = null;

How do I prevent my 'unused' global variables being compiled out?

帅比萌擦擦* 提交于 2019-12-12 07:07:08
问题 I'm using static initialisation to ease the process of registering some classes with a factory in C++. Unfortunately, I think the compiler is optimising out the 'unused' objects which are meant to do the useful work in their constructors. Is there any way to tell the compiler not to optimise out a global variable? class SomeClass { public: SomeClass() { /* do something useful */ } }; SomeClass instance; My breakpoint in SomeClass's constructor doesn't get hit. In my actual code, SomeClass is

No access to global instance (build by factory) on iOS

試著忘記壹切 提交于 2019-12-12 07:05:13
问题 this is a follow-up question to my last one here: iOS: Initialise object at start of application for all controllers to use . I have set my application up as follows (ignore the DB Prefix): DBFactoryClass // Built a DataManaging Object for later use in the app DBDataModel // Is created by the factory, holds all data & access methods DBViewControllerA // Will show some of the data that DBDataModel holds moreViewControllers that will need access to the same DBDataModel Object i will go step by

Python - How to pass global variable to multiprocessing.Process?

社会主义新天地 提交于 2019-12-12 06:09:21
问题 I need to terminate some processes after a while, so I've used sleeping another process for the waiting. But the new process doesn't have access to global variables from the main process I guess. How could I solve it please? Code: import os from subprocess import Popen, PIPE import time import multiprocessing log_file = open('stdout.log', 'a') log_file.flush() err_file = open('stderr.log', 'a') err_file.flush() processes = [] def processing(): print "processing" global processes global log

How to access this variable from an Android onCreate method?

烈酒焚心 提交于 2019-12-12 04:59:08
问题 The problem is that I can't access the userId variable value from inside the onCreate method. I'm accessing the activity from two different activities so I have to check from which one I'm coming from, I do that with the caller but the value returned by the getDetailsUserId method is 0 all the time even though userId is a class variable. If I initialize userId with 5 for example that's the value returned by the getDetailsUserId method... not the value from the onCreate method. public class

Unable to change the value of variable in button click - Sencha

无人久伴 提交于 2019-12-12 04:54:29
问题 I am trying to change value of variable and i did as instruction in this post but value does not changes. My codes are as follow: Ext.define('MyApp.view.OnlineOffline', { extend: 'Ext.Panel', alias: "widget.onlineoffline", config: { onlineStatus: 0, items: [ { xtype: 'container', layout: 'hbox', cls: 'offline-wrap', items:[ { xtype: 'image', cls: 'offlineCheck', id:'onlineButton', width: 85, height:20, listeners: { tap: function (button) { var me = button.up('onlineoffline') if (!Ext.device

Python 3: The visibility of global variables across modules

旧城冷巷雨未停 提交于 2019-12-12 04:26:42
问题 Similar questions have been asked before: here, here and here, and I am aware of these. Say you have 2 modules where one has global variables that you want to read from in another module. Is there a way to make these accessible across modules without having to refer to them as module.variable each time? Example: modulea.py: import moduleb from moduleb import * print("A String: " + astring) print("Module B: " + moduleb.astring) afunction() print("A String: " + astring) print("Module B: " +

How to make char array avaliable in multiple .cpp files?

落花浮王杯 提交于 2019-12-12 03:59:29
问题 I have a working program which must be split into multiple parts, for edition purposes. In this program is needed to keep user login info in char arrays to be able to connect to SQL, and this connection info is used many times in parts of the program that will end up in separated .cpp files, which will compile in a single program. The problem is that if they are declared in just one file, they will be missing in the rest, and if they are declared in all of them, there will be duplicated

Make php variable/constant available to all scripts ad all sites

落花浮王杯 提交于 2019-12-12 03:57:58
问题 I have about 150 websites each on its own Apache virtual host running php7 on ubuntu 16. Each site has a config.php in the root dir with constants in it: define('MYVAR','myval'); I want to make a new constant that I will have to update every 2 months or so. I don't want to open each config and edit them. How can I have each site/virtual host be aware of this constant I want to set. I want to be available everywhere just like $_SERVER['REMOTE_ADDRESS']; is. I do not want to create a file them