global-variables

C# Why can I create an array of labels inside a function but not anywhere else?

你离开我真会死。 提交于 2019-12-24 12:08:07
问题 When I put the code: label[] label_array = {label1, label2}; Inside of a function, it works just fine. Whenever I put it anywhere else, I get the error "A field initializer cannot reference the non-static field, method, or property, file.form1.label1" Is there a different way that I can do it that will allow me to make the label array global? 回答1: You can't write that at the class level, because when the variable initialization runs those labels don't exist yet . If you want the variable at

How do I access variables from a different thread?

半腔热情 提交于 2019-12-24 11:53:58
问题 Getting error: Cross-thread operation not valid: Control 'label1' accessed from a thread other than the thread it was created on. Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Threading; using System.Windows.Forms; namespace WindowsFormsApplication2 { public partial class Form1 : Form { string CONNECTING = "Connecting to server...";

set variables to global scope within a loop

泪湿孤枕 提交于 2019-12-24 11:39:12
问题 I want to define a number of temporary global variables in PHP called $MyGlobalVar1 , $MyGlobalVar2 ... , but the problem is that the keyword 'global' takes the variable name literally: for ($i = 1; $i<= 10; $i++) { $var = '$MyGlobalVar'.$i; global $var; } i.e. $var is now global. Setting quotes will not work because 'global' expects '$' and will stop execution at the single quote: for ($i = 1; $i<= 10; $i++) { $var = '$MyGlobalVar'.$i; global '$var'; } How to set the variables to global

How to access “global” (constant?) capistrano variables from classes? (ruby)

两盒软妹~` 提交于 2019-12-24 10:49:34
问题 So my deploy.rb script in capistrano starts like this, which I guess is pretty normal: require 'capistrano/ext/multistage' require 'nokogiri' require 'curb' require 'json' # override capistrano defaults set :use_sudo, false set :normalize_asset_timestamps, false # some constant of mine set :my_constant, "foo_bar" Later, I can access my constant in functions or tasks within namespaces, like: namespace :mycompany do def some_function() run "some_command #{my_constant}" end desc <<-DESC some

Set javascript global variable to JSONresult?

牧云@^-^@ 提交于 2019-12-24 09:24:40
问题 how do i set a js global variable to a json result set in the onload event? var global = []; $.getJSON("<%: Url.Action("myUrl", "con") %>/", function(data) { $.each(data, function(key, val) { global.push(val); }); }); global does not have a value set on load, i need to access it outside the json call... 回答1: You again. Maybe try var result; $.ajax({ url: '<%: Url.Action("myUrl", "con") %>/', dataType: 'json', async: false, success: function(data) { result = data; } }); // process result here

Error with global variables are not defined in a thread function on python

半腔热情 提交于 2019-12-24 07:54:13
问题 I'm working in a project with OCR using a webcam. I defined a capture() function for save the frame that contains minimum 20 contours with areas greater than 60 pixels in lapses of 3 seconds. I need that the main while cycle works all the time. So I'm using a thread to call capture() function. When I run the code the Python Shell returned an error: NameError: global name frame, ln2 are not defined . The 13th commented line solves the error for the variable frame . Does it means that I have to

Android: Accessing a global Variable inside an onClickListener

不打扰是莪最后的温柔 提交于 2019-12-24 07:38:36
问题 So in Android/Java, I need to access a global variable that is an EditText[] that I create above the onCreate method of my activity inside of an onClickListener . Here is the variable: public class NCDTCPRelayActivity extends Activity { final EditText[] relayLabelEdits = new EditText[n]; Where n is another global variable integer. My problem is that in order to access these EditText inside an onclickListener i had to make final to access inside the onClickListener, but I need to assign

Shared/Global Dictionary in Django Between URLs and Context Processor

随声附和 提交于 2019-12-24 07:15:00
问题 At runtime I'm trying to generate a tree of parent-child relationships between views using the urls.py of different apps. I'm trying to accomplish breadcrumbs by allowing this tree to be defined by an extension of the url function that accepts extra arguments for view_name (name to display on page when used on page, like "Home") and parent_view (specifies the immediate parent so you can generate your breadcrumb). This class is defined in a separate file in its own module utils.breadcrumbs.

Clear( ) ArrayAdapter not working properly - Android

本秂侑毒 提交于 2019-12-24 06:37:15
问题 I have a ArrayAdapter that gathers information from an AsyncTask. The AsyncTask is triggered by an on scroll listener. When the user scrolls to the bottom of the content the AsyncTask is triggered and loads more content. The problem is I have implemented a reset button. What this does is clears the ArrayAdapter and resets the tokens that are sent through JSON to a php script that gathers the information. The reset button doesn't work at all. When I call clear() it sometimes clears the list

How to view internal variables of an R package within an R session?

感情迁移 提交于 2019-12-24 06:36:00
问题 How can I view all the hidden/internal variables of an R package within an R session? By hidden/internal variables I mean the sort of variables described in R Packages - External Data which would be stored in the "/pkg/R/sysdata.Rda" file of a package's source code. My attempts below. None of these are quite right. I feel like I'm missing something. There has to be a straightforward way to do this, right? Download source Of course, I can download the package source and load(file.path("pkg","R