Subclass method -distorted now put again
somewhere at so.com
Thu May 8 03:43:53 PDT 2008
Jarrett Billingsley Wrote:
> "June" <somewhere at so.com> wrote in message
> news:fvtbau$p5q$1 at digitalmars.com...
> > Dont see how this applies .
> > I want to add a function to 'dwt.widgets.Text' that takes two char
> > and alters the text in an instance of dwt.widgets.Text'
> > dwt.widgets.Text' only has a function that takes one char
> > setText(char text)
> It applies because it's exactly what you want to do ;)
> You have several Text objects, yes? And each one has a name? You
> just "add a method" to Text and have it "find" a text box of a given
> you have to store those text boxes and perform the name lookup
> Remember that a class method only operates on a single object; if
> subclassed Text, you wouldn't be able to access other instances of
> besides 'this' unless you stored them somewhere.
> So instead of doing something like
> class MyWindow
> Text foo;
> Text bar;
> foo = new Text("hi!");
> bar = new Text("bye!");
> You can instead store them in an associative array which maps from
> text boxes:
> class MyWindow
> Text[char] textBoxes;
> textBoxes["foo"] = new Text("hi!");
> textBoxes["bar"] = new Text("bye!");
> Then, you can add a method to MyWindow that will take a name and a
> and will set the text box with the given name to the given string:
> // defined as a method of MyWindow
> void setText(char name, char s)
> Keep in mind that D is a statically-compiled language, unlike
> Python, and so dynamic (runtime) lookup of variables and members is,
> general, not possible. Which is why you have to store the mapping
> names to controls yourself.
Completely lost now .
So much extraneous stuff
>>textBoxes["foo"] = new Text("hi!"); using 'dwt.widgets.Text' ,,this
expects a composite parent and an integer style so this does not work
I understand the need to store the names point you are making but
surely I can override the 'dwt.widgets.Text's ' setText(text)
function some way?
More information about the Digitalmars-d-learn