Search Results

Search found 15797 results on 632 pages for 'session variables'.

Page 164/632 | < Previous Page | 160 161 162 163 164 165 166 167 168 169 170 171  | Next Page >

  • Using C++, why can `throw` cause `terminate()`, and when are the stack variables to be freed?

    - by nbolton
    I'm pondering a question on Brainbench. I actually realised that I could answer my question easily by compiling the code, but it's an interesting question nonetheless, so I'll ask the question anyway and answer it myself shortly. Take a look at this snippet: The question considers what happens when we throw from a destructor (which causes terminate() to be called). It's become clear to me by asking the question that the memory is indeed freed and the destructor is called, but, is this before or after throw is called from foo? Perhaps the issue here is that throw is used while the stack is unwinding that is the problem... Actually this is slightly confusing.

    Read the article

  • How do you pass or share variables between django views?

    - by Hugh
    Hi, I'm kind of lost as to how to do this: I have some chained select boxes, with one select box per view. Each choice should be saved so that a query is built up. At the end, the query should be run. But how do you share state in django? I can pass from view to template, but not template to view and not view to view. Or I'm truly not sure how to do this. Please help!

    Read the article

  • Is it possible to add JPA annotation to superclass instance variables?

    - by Kristofer Borgstrom
    Hi, I am creating entities that are the same for two different tables. In order do table mappings etc. different for the two entities but only have the rest of the code in one place - an abstract superclass. The best thing would be to be able to annotate generic stuff such as column names (since the will be identical) in the super class but that does not work because JPA annotations are not inherited by child classes. Here is an example: public abstract class MyAbstractEntity { @Column(name="PROPERTY") //This will not be inherited and is therefore useless here protected String property; public String getProperty() { return this.property; } //setters, hashCode, equals etc. methods } Which I would like to inherit and only specify the child-specific stuff, like annotations: @Entity @Table(name="MY_ENTITY_TABLE") public class MyEntity extends MyAbstractEntity { //This will not work since this field does not override the super class field, thus the setters and getters break. @Column(name="PROPERTY") protected String property; } Any ideas or will I have to create fields, getters and setters in the child classes? Thanks, Kris

    Read the article

  • Does Perl auto-vivify variables used as references in subroutine calls?

    - by FM
    I've declared 2010 to be the year of higher-order programming, so I'm learning Haskell. The introduction has a slick quick-sort demo, and I thought, "Hey, that's easy to do in Perl". It turned to be easier than I expected. Note that I don't have to worry about whether my partitions ($less and $more) are defined. Normally you can't use an undefined value as an array reference. use strict; use warnings; use List::MoreUtils qw(part); my @data = (5,6,7,4,2,9,10,9,5,1); my @sorted = qsort(@data); print "@sorted\n"; sub qsort { return unless @_; my $pivot = shift @_; my ($less, $more) = part { $_ < $pivot ? 0 : 1 } @_; # Works, even though $less and $more are sometimes undefined. return qsort(@$less), $pivot, qsort(@$more); } As best I can tell, Perl will auto-vivify a variable that you try to use as a reference -- but only if you are passing it to a subroutine. For example, my call to foo() works, but not the attempted print. use Data::Dumper qw(Dumper); sub foo { print "Running foo(@_)\n" } my ($x); print Dumper($x); # Fatal: Can't use an undefined value as an ARRAY reference. # print @$x, "\n"; # But this works. foo(@$x); # Auto-vivification: $x is now []. print Dumper($x); My questions: Am I understanding this behavior correctly? What is the explanation or reasoning behind why Perl does this? Is this behavior explained anywhere in the docs?

    Read the article

  • Why is there a constructor method if you can assign the values to variables?

    - by Joel
    I'm just learning PHP, and I'm confused about what the purpose of the __construct() method? If I can do this: class Bear { // define properties public $name = 'Bill'; public $weight = 200; // define methods public function eat($units) { echo $this->name." is eating ".$units." units of food... <br />"; $this->weight += $units; } } Then why do it with a constructor instead? : class Bear { // define properties public $name; public $weight; public function __construct(){ $this->name = 'Bill'; $this->weight = 200; } // define methods public function eat($units) { echo $this->name." is eating ".$units." units of food... <br />"; $this->weight += $units; } }

    Read the article

  • View Models (ViewData), UserControls/Partials and Global variables - best practice?

    - by elado
    Hi I'm trying to figure out a good way to have 'global' members (such as CurrentUser, Theme etc.) in all of my partials as well as in my views. I don't want to have a logic class that can return this data (like BL.CurrentUser) I do think it needs to be a part of the Model in my views So I tried inheriting from BaseViewData with these members. In my controllers, in this way or another (a filter or base method in my BaseController), I create an instance of the inheriting class and pass it as a view data. Everything's perfect till this point, cause then I have my view data available on the main View with the base members. But what about partials? If I have a simple partial that needs to display a blog post then it looks like this: <%@ Control Language="C#" AutoEventWireup="true" Inherits="ViewUserControl<Post>" %> and simple code to render this partial in my view (that its model.Posts is IEnumerable<Post>): <%foreach (Post p in this.Model.Posts) {%> <%Html.RenderPartial("Post",p); %> <%}%> Since the partial's Model isn't BaseViewData, I don't have access to those properties. Hence, I tried to make a class named PostViewData which inherits from BaseViewData, but then my containing views will have a code to actually create the PostViewData in them in order to pass it to the partial: <%Html.RenderPartial("Post",new PostViewData { Post=p,CurrentUser=Model.CurrentUser,... }); %> Or I could use a copy constructor <%Html.RenderPartial("Post",new PostViewData(Model) { Post=p }); %> I just wonder if there's any other way to implement this before I move on. Any suggestions? Thanks!

    Read the article

  • C# going nuts when I declare variables with the same name as the ones in a lambda

    - by Rubys
    I have the following code (generates a quadratic function given the a, b, and c) Func<double, double, double, Func<double, double>> funcGenerator = (a, b, c) => f => f * f * a + b * f + c; Up until now, lovely. But then, if i try to declare a variable named a, b, c or f, visual studio pops a "A local variable named 'f' could not be declared at this scope because it would give a different meaning to 'f' which is used in a child scope." Basically, this fails, and I have no idea why, because a child scope doesn't even make any sense. Func funcGenerator = (a, b, c) = f = f * f * a + b * f + c; var f = 3; // Fails var d = 3; // Fine What's going on here?

    Read the article

  • Why am I having this InstantiationException in Java when accessing final local variables?

    - by Oscar Reyes
    I was playing with some code to make a "closure like" construct ( not working btw ) Everything looked fine but when I tried to access a final local variable in the code, the exception InstantiationException is thrown. If I remove the access to the local variable either by removing it altogether or by making it class attribute instead, no exception happens. The doc says: InstantiationException Thrown when an application tries to create an instance of a class using the newInstance method in class Class, but the specified class object cannot be instantiated. The instantiation can fail for a variety of reasons including but not limited to: - the class object represents an abstract class, an interface, an array class, a primitive type, or void - the class has no nullary constructor What other reason could have caused this problem? Here's the code. comment/uncomment the class attribute / local variable to see the effect (lines:5 and 10 ). import javax.swing.*; import java.awt.event.*; import java.awt.*; class InstantiationExceptionDemo { //static JTextField field = new JTextField();// works if uncommented public static void main( String [] args ) { JFrame frame = new JFrame(); JButton button = new JButton("Click"); final JTextField field = new JTextField();// fails if uncommented button.addActionListener( new _(){{ System.out.println("click " + field.getText()); }}); frame.add( field ); frame.add( button, BorderLayout.SOUTH ); frame.pack();frame.setVisible( true ); } } class _ implements ActionListener { public void actionPerformed( ActionEvent e ){ try { this.getClass().newInstance(); } catch( InstantiationException ie ){ throw new RuntimeException( ie ); } catch( IllegalAccessException ie ){ throw new RuntimeException( ie ); } } } Is this a bug in Java? edit Oh, I forgot, the stacktrace ( when thrown ) is: Caused by: java.lang.InstantiationException: InstantiationExceptionDemo$1 at java.lang.Class.newInstance0(Class.java:340) at java.lang.Class.newInstance(Class.java:308) at _.actionPerformed(InstantiationExceptionDemo.java:25)

    Read the article

  • In Ruby, how can I initialize instance variables in new objects of core classes created from literal

    - by Ollie Saunders
    class Object attr_reader :foo def initialize @foo = 'bar' end end Object.new.foo # => 'bar' ''.foo # => nil //.foo # => nil [].foo # => nil I want them all to return 'bar' Am aware that you can do this already: class Object def foo 'bar' end end But I specifically want to initialize a state variable. Also note that this doesn't work. class String alias_method :old_init, :initialize def initialize(*args) super old_init(*args) end end class Object attr_reader :foo def initialize @foo = 'bar' super end end ''.foo # => nil Nor does this: class String attr_reader :foo def initialize @foo = 'bar' end end ''.instance_variables # => [] I'm beginning to think that this isn't actually possible.

    Read the article

  • How do I grab and use a variables coming back through ValueList from an AJAX call?

    - by Mel
    I'm trying the following code to execute a search and it's not working. On the search.cfm page, the only value coming back is the value I input into the search field (even if I click an autosuggest value, it's not coming back; only the letters I actually type myself come back). <cfform class="titleSearchForm" id="searchForm" action="search.cfm?GameID=#cfautosuggestvalue.GameID#" method="post"> <fieldset> <cfinput type="text" class="titleSearchField" name="TitleName" onChange="form.submit()" autosuggest="cfc:gz.cfcomp.search.AutoSuggestSearch({cfautosuggestvalue})"> <input type="button" class="titleSearchButton" value=" " /> </fieldset> </cfform> Query in CFC: <cfquery name="SearchResult" datasource="myDSN"> SELECT CONCAT(titles.TitleName, ' on ', platforms.PlatformAbbreviation) AS sResult, games.GameID FROM games Inner Join platforms ON games.PlatformID = platforms.PlatformID Inner Join titles ON titles.TitleID = games.TitleID WHERE UCase(titleName) LIKE Ucase('#ARGUMENTS.SearchString#%') ORDER BY titleName ASC; </cfquery> Two things: First of all, I would like to get the GameID back to the page making the AJAX request; I know why it is not coming back: Because I'm only returning sResult var, which does not include the GameID. Is there a way to return the GameID value without displaying it? The second thing: How to I grab a value from the auto-suggest once it is returned? Say I want to grab the GameID, or if I can't do that, the "TitleName" to use that in my query? I tried passing it to the form this way: action="search.cfm?GameID=#cfautosuggestvalue.GameID#" - but that does not work. How do I reference the autosuggestionvalue varaibles for use? Thanks

    Read the article

  • Can threads safely read variables set by VCL events?

    - by Tom1952
    Is it safe for a thread to READ a variable set by a Delphi VCL event? When a user clicks on a VCL TCheckbox, the main thread sets a boolean to the checkbox's Checked state. CheckboxState := CheckBox1.Checked; At any time, a thread reads that variable if CheckBoxState then ... It doesn't matter if the thread "misses" a change to the boolean, because the thread checks the variable in a loop as it does other things. So it will see the state change eventually... Is this safe? Or do I need special code? Is surrounding the read and write of the variable (in the thread and main thread respectively) with critical code calls necessary and sufficient? As I said, it doesn't matter if the thread gets the "wrong" value, but I keep thinking that there might be a low-level problem if one thread tries to read a variable while the main thread is in the middle of writing it, or vice versa. My question is similar to this one: http://stackoverflow.com/questions/1353096/cross-thread-reading-of-a-variable. (Also related to my previous question: http://stackoverflow.com/questions/2449183/using-entercriticalsection-in-thread-to-update-vcl-label)

    Read the article

  • How can I work out what events are being waited for with WinDBG in a kernel debug session

    - by Benj
    I'm a complete WinDbg newbie and I've been trying to debug a WindowsXP problem that a customer has sent me where our software and some third party software prevent windows from logging off. I've reproduced the problem and have verified that only when our software and the customers software are both installed (although not necessarily running at logoff) does the log off problem occur. I've observed that WM_ENDSESSION messages are not reaching the running windows when the user tries to log off and I know that the third party software uses a kernel driver. I've been looking at the processes in WinDbg and I know that csrss.exe would normally send all the windows a WM_ENDSESSION message. When I ran: !process 82356020 6 To look at csrss.exe's stack I can see: WARNING: Frame IP not in any known module. Following frames may be wrong. 00000000 00000000 00000000 00000000 00000000 0x7c90e514 THREAD 8246d998 Cid 0248.02a0 Teb: 7ffd7000 Win32Thread: e1627008 WAIT: (WrUserRequest) UserMode Non-Alertable 8243d9f0 SynchronizationEvent 81fe0390 SynchronizationEvent Not impersonating DeviceMap e1004450 Owning Process 82356020 Image: csrss.exe Attached Process N/A Image: N/A Wait Start TickCount 1813 Ticks: 20748 (0:00:05:24.187) Context Switch Count 3 LargeStack UserTime 00:00:00.000 KernelTime 00:00:00.000 Start Address 0x75b67cdf Stack Init f80bd000 Current f80bc9c8 Base f80bd000 Limit f80ba000 Call 0 Priority 14 BasePriority 13 PriorityDecrement 0 DecrementCount 0 Kernel stack not resident. ChildEBP RetAddr Args to Child f80bc9e0 80500ce6 00000000 8246d998 804f9af2 nt!KiSwapContext+0x2e (FPO: [Uses EBP] [0,0,4]) f80bc9ec 804f9af2 804f986e e1627008 00000000 nt!KiSwapThread+0x46 (FPO: [0,0,0]) f80bca24 bf80a4a3 00000002 82475218 00000001 nt!KeWaitForMultipleObjects+0x284 (FPO: [Non-Fpo]) f80bca5c bf88c0a6 00000001 82475218 00000000 win32k!xxxMsgWaitForMultipleObjects+0xb0 (FPO: [Non-Fpo]) f80bcd30 bf87507d bf9ac0a0 00000001 f80bcd54 win32k!xxxDesktopThread+0x339 (FPO: [Non-Fpo]) f80bcd40 bf8010fd bf9ac0a0 f80bcd64 00bcfff4 win32k!xxxCreateSystemThreads+0x6a (FPO: [Non-Fpo]) f80bcd54 8053d648 00000000 00000022 00000000 win32k!NtUserCallOneParam+0x23 (FPO: [Non-Fpo]) f80bcd54 7c90e514 00000000 00000022 00000000 nt!KiFastCallEntry+0xf8 (FPO: [0,0] TrapFrame @ f80bcd64) This waitForMultipleObjects looks interesting because I'm wondering if csrss.exe is waiting on some event which isn't arriving to allow the logoff. Can anyone tell me how I might find out what event it's waiting for anything else I might do to further investigate the problem?

    Read the article

  • NHibernate and SetSessionAuth audit columns

    - by user86431
    We have audit columns set by triggers. For obscure security reasons predating my tenure and out of my control, we log in with a generic user, and do a 'set session authorization' to change the user to the db user of the user who is logged in. When we converted to NHibernate, it creates a whole new session and jacks everything up when we try to do a set session auth, so we turned the set session auth off... Now we are trying to find out a way to get NHibernate to let us do 'set session authorization' without recycling the session on us, so we can use our existing trigger based audit column stuff with both legacy apps, and our new NHibernate apps. It's not a ideal soloution, or the best way to do it even, but is it possible? I was hoping there was a alternate interface that allowed this kind of access. Does anyone know how to do it, or can you point me towards and good hints? Thanks, Eric-

    Read the article

  • Are there any reasons to make all fields and variables final?

    - by Roman
    In my current project I noticed that all class fields and variable inside methods are declared with final modifier whenever it's possible. Just like here: private final XMLStreamWriter _xmlStreamWriter; private final Marshaller _marshaller; private final OutputStream _documentStream; private final OutputStream _stylesStream; private final XMLStreamWriter _stylesStreamWriter; private final StyleMerger _styleMerger; public DocumentWriter(PhysicalPackage physicalPackage) throws IOException { final Package pkg = new Package(physicalPackage); final Part wordDocumentPart = pkg.createPart( "/word/document.xml", "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"); // styles.xml final Pair<Part, String> wordStylesPart = wordDocumentPart.createRelatedPart(...); ... } Are there any reasons to do so? p.s. As I know project is not supposed to be multithreaded (at least I've heard nothing about it).

    Read the article

  • How to access method variables from within an anonymous function in JavaScript?

    - by Hussain
    I'm writing a small ajax class for personal use. In the class, I have a "post" method for sending post requests. The post method has a callback parameter. In the onreadystatechange propperty, I need to call the callback method. Something like this: this.requestObject.onreadystatechange = function() { callback(this.responseText); } However, I can't access the callback variable from within the anonomous function. How can I bring the callback variable into the scope of the onreadystatechange anonomous function? edit: Here's the full code so far: function request() { this.initialize = function(errorHandeler) { try { try { this.requestObject = new XDomainRequest(); } catch(e) { try { this.requestObject = new XMLHttpRequest(); } catch (e) { try { this.requestObject = new ActiveXObject("Msxml2.XMLHTTP"); //newer versions of IE5+ } catch (e) { this.requestObject = new ActiveXObject("Microsoft.XMLHTTP"); //older versions of IE5+ } } } } catch(e) { errorHandeler(); } } this.post = function(url,data) { var response;var escapedData = ""; if (typeof data == 'object') { for (i in data) { escapedData += escape(i)+'='+escape(data[i])+'&'; } escapedData = escapedData.substr(0,escapedData.length-1); } else { escapedData = escape(data); } this.requestObject.open('post',url,true); this.requestObject.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); this.requestObject.setRequestHeader("Content-length", data.length); this.requestObject.setRequestHeader("Connection", "close"); this.requestObject.onreadystatechange = function() { if (this.readyState == 4) { // call callback function } } this.requestObject.send(data); }

    Read the article

  • R ggplot barplot; Fill based on two separate variables

    - by user1476968
    A picture says more than a thousand words. As you can see, my fill is based on the variable variable. Within each bar there is however multiple data entities (black borders) since the discrete variable complexity make them unique. What I am trying to find is something that makes each section of the bar more distinguishable than the current look. Preferable would be if it was something like shading. Here's an example (not the same dataset, since the original was imported): dat <- read.table(text = "Complexity Method Sens Spec MMC 1 L Alpha 50 20 10 2 M Alpha 40 30 80 3 H Alpha 10 10 5 4 L Beta 70 50 60 5 M Beta 49 10 80 6 H Beta 90 17 48 7 L Gamma 19 5 93 8 M Gamma 18 39 4 9 H Gamma 10 84 74", sep = "", header=T) library(ggplot2) library(reshape) short.m <- melt(dat) ggplot(short.m, aes(x=Method, y= value/100 , fill=variable)) + geom_bar(stat="identity",position="dodge", colour="black") + coord_flip()

    Read the article

  • Does `throw` cause stack variables (full types) to be freed from memory in C++?

    - by nbolton
    I'm pondering a question on Brainbench. I actually realised that I could answer my question easily by compiling the code, but it's an interesting question nonetheless, so I'll ask the question anyway and answer it myself shortly. Take a look at this snippet: The question considers what happens when we throw from a destructor (which causes terminate() to be called). It's become clear to me by asking the question that the memory is indeed freed and the destructor is called, but, is this before or after throw is called from foo? Perhaps the issue here is that throw is used while the stack is unwinding that is the problem... Actually this is slightly confusing.

    Read the article

  • Why is this variables declared as private and also readonly?

    - by Sergio Tapia
    In the following code: public class MovieRepository : IMovieRepository { private readonly IHtmlDownloader _downloader; public MovieRepository(IHtmlDownloader downloader) { _downloader = downloader; } public Movie FindMovieById(string id) { var idUri = ...build URI...; var html = _downloader.DownloadHtml(idUri); return ...parse ID HTML...; } public Movie FindMovieByTitle(string title) { var titleUri = ...build URI...; var html = _downloader.DownloadHtml(titleUri); return ...parse title HTML...; } } I asked for something to review my code, and someone suggested this approach. My question is why is the IHtmlDownloader variable readonly?

    Read the article

  • Session is Closed! NHibernate shouldn't be trying to grab data

    - by Jeremy Holovacs
    I have a UnitOfWork/Service pattern where I populate my model using NHibernate before sending it to the view. For some reason I still get the YSOD, and I don't understand why the object collection is not already populated. My controller method looks like this: public ActionResult PendingRegistrations() { var model = new PendingRegistrationsModel(); using (var u = GetUnitOfWork()) { model.Registrations = u.UserRegistrations.GetRegistrationsPendingAdminApproval(); } return View(model); } The service/unit of work looks like this: public partial class NHUserRegistrationRepository : IUserRegistrationRepository { public IEnumerable<UserRegistration> GetRegistrationsPendingAdminApproval() { var r = from UserRegistration ur in _Session.Query<UserRegistration>() where ur.Status == AccountRegistrationStatus.PendingAdminReview select ur; NHibernateUtil.Initialize(r); return r; } } What am I doing wrong?

    Read the article

  • When do instance variables get initialized and values assigned?

    - by AKh
    When doees the instance variable get initialized? Is it after the constructor block is done or before it? Consider this example: public abstract class Parent { public Parent(){ System.out.println("Parent Constructor"); init(); } public void init(){ System.out.println("parent Init()"); } } public class Child extends Parent { private Integer attribute1; private Integer attribute2 = null; public Child(){ super(); System.out.println("Child Constructor"); } public void init(){ System.out.println("Child init()"); super.init(); attribute1 = new Integer(100); attribute2 = new Integer(200); } public void print(){ System.out.println("attribute 1 : " +attribute1); System.out.println("attribute 2 : " +attribute2); } } public class Tester { public static void main(String[] args) { Parent c = new Child(); ((Child)c).print(); } } OUTPUT: Parent Constructor Child init() parent Init() Child Constructor attribute 1 : 100 attribute 2 : null When the memory for the atribute 1 & 2 are allocated in the heap ? Curious to know why is attribute 2 is NULL ? Are there any design flaws?

    Read the article

  • NHibernate unintentional lazy property loading

    - by chiccodoro
    I introduced a mapping for a business object which has (among others) a property called "Name": public class Foo : BusinessObjectBase { ... public virtual string Name { get; set; } } For some reason, when I fetch "Foo" objects, NHibernate seems to apply lazy property loading (for simple properties, not associations): The following code piece generates n+1 SQL statements, whereof the first only fetches the ids, and the remaining n fetch the Name for each record: ISession session = ...IQuery query = session.CreateQuery(queryString); ITransaction tx = session.BeginTransaction(); List<Foo> result = new List<Foo>(); foreach (Foo foo in query.Enumerable()) { result.Add(foo); } tx.Commit(); session.Close(); produces: NHibernate: select foo0_.FOO_ID as col_0_0_ from V1_FOO foo0_<br/> NHibernate: SELECT foo0_.FOO_ID as FOO1_2_0_, foo0_.NAME as NAME2_0_ FROM V1_FOO foo0_ WHERE foo0_.FOO_ID=:p0;:p0 = 81<br/> NHibernate: SELECT foo0_.FOO_ID as FOO1_2_0_, foo0_.NAME as NAME2_0_ FROM V1_FOO foo0_ WHERE foo0_.FOO_ID=:p0;:p0 = 36470<br/> NHibernate: SELECT foo0_.FOO_ID as FOO1_2_0_, foo0_.NAME as NAME2_0_ FROM V1_FOO foo0_ WHERE foo0_.FOO_ID=:p0;:p0 = 36473 Similarly, the following code leads to a LazyLoadingException after session is closed: ISession session = ... ITransaction tx = session.BeginTransaction(); Foo result = session.Load<Foo>(id); tx.Commit(); session.Close(); Console.WriteLine(result.Name); Following this post, "lazy properties ... is rarely an important feature to enable ... (and) in Hibernate 3, is disabled by default." So what am I doing wrong? I managed to work around the LazyLoadingException by doing a NHibernateUtil.Initialize(foo) but the even worse part are the n+1 sql statements which bring my application to its knees. This is how the mapping looks like: <class name="Foo" table="V1_FOO"> ... <property name="Name" column="NAME"/> </class> BTW: The abstract "BusinessObjectBase" base class encapsulates the ID property which serves as the internal identifier.

    Read the article

< Previous Page | 160 161 162 163 164 165 166 167 168 169 170 171  | Next Page >