Infinit loop
Ary Borenszweig
ary at esperanto.org.ar
Sun May 11 07:37:24 PDT 2008
wongtd escribió:
> see this here
>
> module Box; import dwt.DWT; import dwt.widgets.Composite; import dwt.widgets.Control; import dwt.widgets.Text; import dwt.widgets.Shell; import dwt.widgets.Display; import tango.io.Stdout; class Box { private Control[char[]] controls; // Use associative array this (Composite parent ,int style ) { auto box = new Composite(parent,DWT.SINGLE); box.setSize(700,40); auto No = new Text(box,DWT.LEFT); No.setBounds(1,15,10,15); No.setText(""); auto Date = new Text(box,DWT.LEFT); Date.setBounds( 21, 15, 60, 15); Date.setText(""); auto Content = new Text(box,DWT.LEFT); Content.setBounds( 90, 15,70, 15); Content.setText(""); box.setVisible = true; controls["No"] = No; controls["Date"] = Date; controls["Content"] = Content; box.setTabList(controls.values); } void setText(char[] name, char[] text) { controls[name].setText(text); } } void main () { Display display = new Display
(); Shell shell = new Shell (display); shell.setText("Boxes"); Box mybox1 = new Box(shell,DWT.SINGLE); mybox1.setText("No","wire"); Box mybox2 = new Box(shell,DWT.SINGLE); mybox2.setText("Content","Fishingline"); shell.pack(); shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } /*---------------------------------------------------------------------------- Box.d(44): Error: no property 'setText' for type 'dwt.widgets.Control.Control' Box.d(44): Error: function expected before (), not 1 of type int */
The formatted code is:
---
module Box;
import dwt.DWT;
import dwt.widgets.Composite;
import dwt.widgets.Control;
import dwt.widgets.Text;
import dwt.widgets.Shell;
import dwt.widgets.Display;
import tango.io.Stdout;
class Box {
private Control[char[]] controls; // Use associative array
this(Composite parent, int style) {
auto box = new Composite(parent, DWT.SINGLE);
box.setSize(700, 40);
auto No = new Text(box, DWT.LEFT);
No.setBounds(1, 15, 10, 15);
No.setText("");
auto Date = new Text(box, DWT.LEFT);
Date.setBounds(21, 15, 60, 15);
Date.setText("");
auto Content = new Text(box, DWT.LEFT);
Content.setBounds(90, 15, 70, 15);
Content.setText("");
box.setVisible = true;
controls["No"] = No;
controls["Date"] = Date;
controls["Content"] = Content;
box.setTabList(controls.values);
}
void setText(char[] name, char[] text) {
controls[name].setText(text); // ** Here's the error **
}
}
void main() {
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("Boxes");
Box mybox1 = new Box(shell, DWT.SINGLE);
mybox1.setText("No", "wire");
Box mybox2 = new Box(shell, DWT.SINGLE);
mybox2.setText("Content", "Fishingline");
shell.pack();
shell.open();
while(!shell.isDisposed()) {
if(!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
---
You are getting that error because the class Control doesn't have a
method named setText. You probably want to declare controls as follows:
private Text[char[]] controls; // Use associative array
(and probably use another name instead of controls)
>
> I play with and put in
>
> }
>
> void setText(char[] text)
> {
> setText(text);//dont understand why this does not cause infinite loop?
> }
When you defined that method, did you invoke it? If not, that's why you
didn't get infinite loops. But you should, if you invoke it.
>
> void setText(char[] name, char[]text)
> {
> // name.setText(text);
> }
> }
>
> with layout in shell above compiles and runs giving 9 text boxes with right text.
>
> Question When setText(name,text ) is called Why does setText(text) not cause infinit loop?
That's a different question. setText(name, text) and setText(text) are
different methods: two methods are considered the same if they have the
same name, same formal arguments, and same return type.
> It calls itself seems so
> I tried to put in 'override' but would not compile
Because setText(char[] name, char[] text) is not a method of Object (the
class your Box is inheriting from). It wouldn't work either if you
extended from Text, because Text has the method setText(char[] text),
which is a different method than setText(char[] name, char[] text).
More information about the Digitalmars-d-learn
mailing list