How to set non-static variable in static method within class

Rory McGuire rjmcguire at gmail.com
Fri Nov 20 02:05:57 PST 2009


Sam Hu <samhu.samhu at nospam.com> wrote:
 
> Ary Borenszweig Wrote:
> 
>> 
>> You can't access non-static data from a static method. Non-static data 
>> is related to an instance of a class, and a static method is not bound 
>> to any instance.
>> 
>> Why do you want to do that?
> 
> Say I want to implement an utility dialog, InputDialog in DFL which is a 
subclass of Form,using its static method I can call InputDialog.getString to 
retrieve a string from the textbox of this dialog  other than create an instance 
of InputDialog,at the mean time I want to customize the caption text and the 
prompt message of the InputDialog in the static method InputDialog.getString.But 
I can't modify Form.text, (form.)TextBox.text  in the static method.Currently I 
have to  use its non-static version of getString method and create an instance 
of the dialog each time when I call getString.
> 

since non-static data is only created with an instance you would have to use 
some sort of Singleton or something, I suppose.



More information about the Digitalmars-d-learn mailing list