Search Results

Search found 24043 results on 962 pages for 'private methods'.

Page 74/962 | < Previous Page | 70 71 72 73 74 75 76 77 78 79 80 81  | Next Page >

  • How can I write an extension method that converts a System.Drawing.Bitmap to a byte array?

    - by Patrick Szalapski
    How can I write an extension method that converts a System.Drawing.Bitmap to a byte array? Why not: <Extension()> _ Public Function ToByteArray(ByVal image As System.Drawing.Bitmap) As Byte() Using ms = New MemoryStream() image.Save(ms, image.RawFormat) Return ms.ToArray() End Using End Function Yet when I use that, I get "System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+." What am I doing wrong?

    Read the article

  • If I cast an IQueryable as an IEnumerable then call a Linq extension method, which implementation gets called?

    - by James Morcom
    Considering the following code: IQueryable<T> queryable; // something to instantiate queryable var enumerable = (IEnumerable<T>) queryable; var filtered = enumerable.Where(i => i > 3); In the final line, which extension method gets called? Is it IEnumerable<T>.Where(...)? Or will IQueryable<T>.Where(...) be called because the actual implementation is still obviously a queryable? Presumably the ideal would be for the IQueryable version to be called, in the same way that normal polymorphism will always use the more specific override. In Visual Studio though when I right-click on the Where method and "Go to Definition" I'm taken to the IEnumerable version, which kind of makes sense from a visual point-of-view. My main concern is that if somewhere in my app I use Linq to NHibernate to get a Queryable, but I pass it around using an interface that uses the more general IEnumerable signature, I'll lose the wonders of deferred database execution!

    Read the article

  • override __set in __construct() in php?

    - by user151841
    I have a class based on database values. I'm using __set to automatically sync database values with the class properties. Set checks an array of database fields that it is allowed to update in the database. The field 'id' isn't in the list, so __set will throw an exception if you try to do $objDbRow->id = 5;. However, there is one time when I do want to set the id property of the object, and that's on instantiation. So in __constuct, I have $this->id = $id (where $id is passed to __construct). However, __set seems to be intercepting the setting here, because an exception is being thrown on construction. What's the way to get around this? I suppose I also have a boolean flag, like $instantiated, that __set() would check before it does it's field whitelist checking. But that feels inelegant.

    Read the article

  • Start a thread using a method pointer

    - by Michael
    Hi ! I'm trying to develop a thread abstraction (POSIX thread and thread from the Windows API), and I would very much like it to be able to start them with a method pointer, and not a function pointer. What I would like to do is an abstraction of thread being a class with a pure virtual method "runThread", which would be implanted in the future threaded class. I don't know yet about the Windows thread, but to start a POSIX thread, you need a function pointer, and not a method pointer. And I can't manage to find a way to associate a method with an instance so it could work as a function. I probably just can't find the keywords (and I've been searching a lot), I think it's pretty much what Boost::Bind() does, so it must exist. Can you help me ?

    Read the article

  • Compilation Error related

    - by aparna
    Given: 11. public static void test(String str) { 12. int check = 4; 13. if (check = str.length()) { 14. System.out.print(str.charAt(check -= 1) +", "); 15. } else { 16. System.out.print(str.charAt(0) + ", "); 17. } 18. } and the invocation: 21. test("four"); 22. test("tee"); 23. test("to"); What is the result? A. r, t, t, B. r, e, o, C. Compilation fails. D. An exception is thrown at runtime. Answer: C Can you explain why the compilation fails please?

    Read the article

  • Objective-C Result from a Static Method saved to class instance variable giving "EXC_BAD_ACCESS" when used.

    - by KinGBin
    I am trying to store the md5 string as a class instance variable instead of the actual password. I have a static function that will return a md5 string which I'm trying to store in an instance variable instead of the actual password. I have the following setter for my class instance variable: -(void)setPassword:(NSString *)newpass{ if(newpass != password){ password = [utils md5HexDigest:newpass]; } } This will pass back the correct md5 string and save it to the password variable in my init function: [self setPassword:pword];. If I call another instance method and try to access self.password" I will get "EXC_BAD_ACCESS". I understand that the memory is getting released, but I have no clue to make sure it stays. I have tried alloc init with autorelease with no luck. This is the md5HexDigest function getting called during the init (graciously found in another stackoverflow question): + (NSString*)md5HexDigest:(NSString*)input { const char* str = [input UTF8String]; unsigned char result[CC_MD5_DIGEST_LENGTH]; CC_MD5(str, strlen(str), result); NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2]; for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) { [ret appendFormat:@"%02x",result[i]]; } return ret; } Any help/pointers would be greatly appreciated. I would rather have the md5 string saved in memory than the actual password calling the md5 every time I needed to use the password. Thanks in advance.

    Read the article

  • SQLite user_version() expression

    - by ralf.w.
    how can I get user_version into an expression (for SELECT or WHERE) ? I would also appreciate any clue to how to save ANY global variable in SQLite. Does anyone know of such an extension (dll) ? BTW: I know that PRAGMA user_version; gives me the right answer, but I cannot use that inside a WHERE-clause !

    Read the article

  • Objective-C: Cannot Change Value of Instance Variable Inside a Function

    - by user262325
    Hello everyone, I cannot change the value of an instance variable inside a function. I have defined a class: // info.h #import <Foundation/Foundation.h> @interface NSMyObject : NSObject { NSInteger i; } -(void) setI:(NSInteger)v; @end #import "info.h" @implementation NSMyObject -(void) setI:(NSInteger)v ; { i=v; } - (void)dealloc { [super dealloc]; } @end I call a function 'myFunction' with parameter temObj which is a NSMyObject instance. myFunction(temObj);//temObj is NSMyObject In the function, I can change the value of the instance variable of parameter obj. -(void)myFunction:(NSMyObject*) obj; { [obj setI:0]; } ... expecting this to change the content of temObj. But when I check the results of operation on obj in function myFunction the value of temObj.i has not changed. Welcome any comment Thanks

    Read the article

  • Why is the output like this?

    - by javatechi
    class another { public void method(Object o) { System.out.println("This is in method which takes object"); } public void method(String s) { System.out.println("This is method which takes string"); } } public class NewClass { public static void main(String args[]) { another an = new another(); an.method(null); } } When I try to execute this, I get This is method which takes string as the output. Why not "This is in method which takes object"? Object can also be null and string can also be null, why doesn't it invoke first method?

    Read the article

  • When calling a static method on parent class, can the parent class deduce the type on the child (C#)

    - by Matt
    Suppose we have 2 classes, Child, and the class from which it inherits, Parent. class Parent { public static void MyFunction(){} } class Child : Parent { } Is it possible to determine in the parent class how the method was called? Because we can call it two ways: Parent.MyFunction(); Child.MyFunction(); My current approach was trying to use: MethodInfo.GetCurrentMethod().ReflectedType; // and MethodInfo.GetCurrentMethod().DeclaringType; But both appear to return the Parent type. If you are wondering what, exactly I am trying to accomplish (and why I am violating the basic OOP rule that the parent shouldn't have to know anything about the child), the short of it is this (let me know if you want the long version): I have a Model structure representing some of our data that persists to the database. All of these models inherit from an abstract Parent. This parent implements a couple of events, such as SaveEvent, DeleteEvent, etc. We want to be able to subscribe to events specific to the type. So, even though the event is in the parent, I want to be able to do: Child.SaveEvent += new EventHandler((sender, args) => {}); I have everything in place, where the event is actually backed by a dictionary of event handlers, hashed by type. The last thing I need to get working is correctly detecting the Child type, when doing Child.SaveEvent. I know I can implement the event in each child class (even forcing it through use of abstract), but it would be nice to keep it all in the parent, which is the class actually firing the events (since it implements the common save/delete/change functionality).

    Read the article

  • How to read a Dependency property from a method

    - by PaN1C_Showt1Me
    XAML: <my:Control ItemsSource="{StaticResource MySource}" A="true" /> Assume a Control with a dependency property A with a default value false; and a method to handle the Source Collection: protected override void OnItemsSourceChanged(System.Collections.IEnumerable oldValue, System.Collections.IEnumerable newValue) {} in which you want to look at A and readout its value (which is true). how would you ensure, that A is already initialized and has a given value? Or how should this be done correctly ? In my case A is something like AllowLateBinding .. Could coerce callback help me?

    Read the article

  • Calling a method from another view in objective-c. (iphone sdk).

    - by MarcZero
    Hello. I am currently creating a multi-view game on the iPhone platform. I have my main view start to play some background music upon loading. I then go to another view and start the game. I am trying to get the background music from the original view to stop once I start the game. I am having trouble getting the stop playing music message to my original view. Here is the relevant info: The main view where the sound is played from is just a subView of the programViewController class called *viewController. The heading is in the programAppDelegate class. The sound is done using the AVAudioPlayer class and plays fine when the program starts up and when I navigate to other subviews that are added on by going through the menu system. In the view that I want to start the game, I attempt to call the instance of the class to turn of the player but anytime I use this format of code: [viewController #######]; It gives a build error of "viewController undeclared" no matter what I put after the "viewController" in the message.I have attempted to import the programAppDelegate.h file but it still gives the same error. I realize this might be a simple misunderstanding of the objective-c language but I cannot find any info on this issue. I am a recent convert from Java so I am trying to wrap my head around everything. Thank you for your time!

    Read the article

  • Class Method not working in objective c

    - by byteSlayer
    In my code I have a class called 'ProfileShareViewController', In which I have imported another class I have created called 'OwnProfileData', And I have also created an Instance of that class (class = OwnProfileData) as a property Of 'ProfileShareViewController' and synthesized it (instance called 'OwnProfile'). In another class I have called 'EditProfileViewController', I have imported the 'ProfileShareViewController', and now I am trying to change a property of the OwnProfile object from the ProfileShareViewController within the EditProfileViewController class. For some reason that doesn't work. I have Tried typing: [[ProfileShareViewController ownProfile] setName:@"Ido"]; (The property I am trying to set is Name, and as it is synthesized in OwnProfileData, I am using 'setName'). This doesn't work and I get the warning: "No known class method for selector 'ownMethod'. Any Idea as for why that might happen and how I can fix this? Thanks for your comments! Any support is highly appreciated!

    Read the article

  • C# mysql one return last_insert_id

    - by Bernhard
    I am trying to create a method in which I can exequte mysql UPDATE, DELETE or INSERT query. The method must work when with an INSERT I ask or do not ask the last_insert_id(). Below is the code that I have at the moment: public int executeUID(MySqlCommand msCommand) { try { this.Open(); msCommand.Connection = this.msCon; return int.Parse(msCommand.ExecuteScalar().ToString()); } catch (MySqlException ex) { throw ex; } finally { this.Close(); } } The problem with this is is that when I use an insert query that returns a last_insert_id() the method works greatly. But when the query doesn't return an last_insert_id() the method malfunctions. How can I get this method to work?

    Read the article

  • How do I put logic in a View a scope or method in a Model?

    - by Angela
    I have the following in the view: <% unless contact_email.statuses.empty?%> (<%= contact_email.statuses.find(:last).status%>) <% end %> contact_email is an instance of a specific model. Could I do something like this? class ContactEmail < ActiveRecord::Base attr_accessible :contact_id, :email_id, :status, :subject, :body, :date_created, :date_sent def status unless contact_email.statuses.empty? contact_email.statuses.find(:last).status end end end is there a better way to do this? is there a way to use the || operator for a default if empty? Basically, I would like to be able to do the following in the View: <%= contact_email.status = IF there is a value, then display it, if not, show nothing.

    Read the article

  • In Python, is there a way to call a method on every item of an iterable? [closed]

    - by Thane Brimhall
    Possible Duplicate: Is there a map without result in python? I often come to a situation in my programs when I want to quickly/efficiently call an in-place method on each of the items contained by an iterable. (Quickly meaning the overhead of a for loop is unacceptable). A good example would be a list of sprites when I want to call draw() on each of the Sprite objects. I know I can do something like this: [sprite.draw() for sprite in sprite_list] But I feel like the list comprehension is misused since I'm not using the returned list. The same goes for the map function. Stone me for premature optimization, but I also don't want the overhead of the return value. What I want to know is if there's a method in Python that lets me do what I just explained, perhaps like the hypothetical function I suggest below: do_all(sprite_list, draw)

    Read the article

  • Delphi static method of a class returning property value

    - by mitko.berbatov
    I'm making a Delphi VCL application. There is a class TStudent where I have two static functions: one which returns last name from an array of TStudent and another one which returns the first name of the student. Their code is something like: class function TStudent.FirstNameOf(aLastName: string): string; var i : integer; begin for i := 0 to Length(studentsArray) - 1 do begin if studentsArray[i].LastName = aLastName then begin result := studentsArray[i].FirstName; Exit; end; end; result := 'no match was found'; end; class function TStudent.LastNameOf(aFirstName: string): string; var i : integer; begin for i := 0 to Length(studentsArray) - 1 do begin if studentsArray[i].FirstName = aFirstName then begin result := studentsArray[i].LastName; Exit; end; end; result := 'no match was found'; end; My question is how can I avoid writing almost same code twice. Is there any way to pass the property as parameter of the functions.

    Read the article

  • returning values from function or method multiple times by only calling the class once

    - by Sokhrat Sikar
    I have a members.php file that shows my websites members. I echo members name by using foreach method. A method of Members class returns an array, then I use foreach loop in the members.php file to echo the members. I am trying to aovid writing php code in my members.php file. Is there a way to avoid using foreach inside members.php file? For example, is it possible to return value from a method couple of times? (by only calling the object once). Just like how we normally call the functions? This question doesn't make sense, but I am just trying to see if there is a away around this issue?

    Read the article

< Previous Page | 70 71 72 73 74 75 76 77 78 79 80 81  | Next Page >