Subclass method -distorted now put again

Jarrett Billingsley kb3ctd2 at yahoo.com
Wed May 7 12:17:34 PDT 2008


"BCS" <BCS at pathlink.com> wrote in message 
news:fvsdh5$2hii$11 at digitalmars.com...

> so "setText("speaker", "foo") would call speaker.setText("foo")?
>
> D doesn't support this directly, however you could do it manually
>
> void setText(char[] name, char[] text)
> {
> switch(name)
> {
> case "speaker": speaker.setText(text); break;
> case "radio":     radio.setText(text); break;
> default: assert(false);
> }
> }

In this case, it seems like keeping the controls in an AA would make a lot 
more sense.

class MyWindow
{
    Control[char[]] controls;

    this()
    {
        controls["speaker"] = new Slider();
        controls["radio"] = new Button();
    }

    void setText(char[] name, char[] text)
    {
        controls[name].setText(text);
    }
} 




More information about the Digitalmars-d-learn mailing list