Subclass method -distorted now put again

BCS BCS at pathlink.com
Wed May 7 07:17:55 PDT 2008


June wrote:
> Ary Borenszweig Wrote:
> 
> 
>>June escribió:
>>
>>>dwt.widget.Text has method
>>> 
>>>void setText  (char[] string); 
>>>Sets the contents of the receiver to the given string.
>>>
>>>In my application I use many of these text boxes each with a name so I need a function 
>>>
>>>void setText(char[] name, char[] text){
>>>   name.setText(text);}
>>
>>name.setText(text) ?
>>
>>But name is of type char[]
>>
>>
>>>How can  I bring this into my program ?
>>
>>Maybe you could show what you do now, and how you would like to have it 
>>if you were able to do what you want. I don't understand what you are 
>>trying to do. :(
> 
> 
> 
> In a class 'Room'
> I make a text box called  "speaker', and another called 'radio' etc
> Text speaker = new Text;
> 
> all blank atm
> 
> In another module  'town' I create instance of 'room' and 
> now I want to set the text in each
> speaker.setText("Wallplate");
> radio.setText("Valves")
> 
> So Text class has  method  'setText(char[])
> 
> In 'town' I want to make another method like 
> setText(name[],text[]);
> 
> different parameters to setText () in Text- I need to find out how to do it please?


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);
	}
}





More information about the Digitalmars-d-learn mailing list