instance

Why can I create an instance of a class without storing it to a variable and still have everything work?

梦想的初衷 提交于 2019-12-01 19:07:36
I have a non-static class called ImplementHeaderButtons which contains a non-static public method called Implement . The name of the class and method are not important, what's important is that they are not static, so they need to be instantiated in order to be used, right? So I used to do this: var implementHeaderButtons = new ImplementHeaderButtons(); implementHeaderButtons.Implement(this, headerButtons); But then I decided to play around a bit with it (actually I was looking for a way to make it a one-liner) and I concluded that the following code works just as well: new

Do you have to explicitly create instance of form in VB.NET? [duplicate]

元气小坏坏 提交于 2019-12-01 18:42:51
This question already has an answer here: Why is there a default instance of every form in VB.Net but not in C#? 2 answers If a project contains a Form class, can the form be shown by: Form1.Show or does an instance of the form need to be created first? Dim frm As New Form1 frm.Show Yes it can, it is the default Form instance it was left in the Language for VB6 compatability. If it was me I would avoid it like the plague, it only muddies the waters. Create your own instances instead. As has been suggested, using the form name uses the default instance while you second snippet explicitly

How to create an object instance of class with internal constructor via reflection?

陌路散爱 提交于 2019-12-01 18:02:07
Example: class Program { static void Main(string[] args) { var myClass = Activator.CreateInstance(typeof(MyClass)); } } public class MyClass { internal MyClass() { } } Exception: System.MissingMethodException No parameterless constructor defined for this object. Solution: var myClass = Activator.CreateInstance(typeof(MyClass), nonPublic:true); I cannot understand, why I cannot create an instance inside the assembly with internal constructor. This constructor should be available inside the execution assembly. It should work like public for this assembly. It is not that impossible. you've to

PHP Passing an instance of a class to another class

心已入冬 提交于 2019-12-01 16:06:56
I'm still kind of new to PHP OO programming techniques and I have a very simple broad question, is it generally bad practice to instantiate a class in a class then pass that instance to another class? What I want is to be able to create an instance of a specific class I know I will always need through each user request. Class two is more than anything just a helper class, ideally in my application it would be a "loader" that loads the views. First class which calls the other two classes: require 'classTwo.php'; require 'classThree.php'; class first { public $classTwo, $classThree; public

PHP Passing an instance of a class to another class

∥☆過路亽.° 提交于 2019-12-01 15:23:23
问题 I'm still kind of new to PHP OO programming techniques and I have a very simple broad question, is it generally bad practice to instantiate a class in a class then pass that instance to another class? What I want is to be able to create an instance of a specific class I know I will always need through each user request. Class two is more than anything just a helper class, ideally in my application it would be a "loader" that loads the views. First class which calls the other two classes:

Declaring instance variables in iOS - Objective-C

北慕城南 提交于 2019-12-01 13:43:39
Ok, I've read a lot around these days about this topic and I alwyas get confused because the answers is different every search I make. I need to know the best way to declare instance variables in iOS. So far I know I should only declare them inside .m file and leave .h clean. But I can't do it: the compiler gives me compilation erros. Here is some code from .m only. @interface UIDesign () // .m file { NSString *test2 = @"test2"; } @property (nonatomic, assign) int privateInt; @end @implementation UIDesign { NSString *test1 = @"test1"; } Both strings are declared incorrectly and I don't know

Prevent new activity instance after clicking on notification

廉价感情. 提交于 2019-12-01 13:42:37
问题 application (non-wanted) behavior - application is started, some text is put into text-box and notification is created through button action. user "clicks" the home button, application is "minimized", notification is available in bar user selects the notification and the application is "maximized" BUT - instead of the original instance, new instance is started (e.g. in the newest instance is missing the original text; when the latest instance is closed there is still the original instance

How to set focus the already running application?

孤街醉人 提交于 2019-12-01 13:34:17
I am using a ServerSocket port to run one instance only of my Java Swing application, so if a user tries to open another instance of the program, i show him a warning that "Another instance is already open". This works fine, but instead of showing this message i want to set focus on the running application itself, like some programs does (MSN Messenger), even if it was minimized. Is there a solution for this for various operating systems ? Since you use a server socket I assume that you use the java.net.BindException to detect that you application is already running. If you start a second

JavaFx: how to reference main Controller class instance from CustomComponentController class?

懵懂的女人 提交于 2019-12-01 12:57:54
WHAT I HAVE is a standard JavaFX application: Main.java, MainController.java & main.fxml . To add custom component, I created CustomComponentController.java and custom_component_controller.fxml . PROBLEM is that in CustomComponentController methods I need to reference other methods and standard components from MenuController . I add public static MainController mc; to MainController class body, so that it can be seen from CustomComponentController ( MainController.mc.neededMethod() ). Then I try to pass everything to it in MainController.initialize() method ( mc = this; ) - when debugging this

Integrating native JavaScript classes in an Angular app

谁说我不能喝 提交于 2019-12-01 12:50:01
I have a native JavaScript class: var Holder = new function(elements) { this.elements = elements; this.anyFunction() { // use of this.elements }; }; How to use it in an Angular-way? For example, if I would like to use: .controller('AnyController', ['Holder', function (Holder) { var elements = [ {id: 1, label: 'foo'}, {id: 2, label: 'bar'} ]; $scope.holder = new Holder(elements); }]) How should I register my Holder class then? What are the options (if any)? In parallel, is it that bad to use native JavaScript classes in an Angular app (i.e. without integrating it within the framework)? You