www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Infinit loop

reply wongtd <wongtd smm.com> writes:
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 */

I play with and put in 

}

  void setText(char[] text)
{ 
  setText(text);//dont understand why this does not cause infinite loop?
}

  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?
It calls itself seems so
I tried to put in 'override' but would not compile
May 10 2008
next sibling parent "Simen Kjaeraas" <simen.kjaras gmail.com> writes:
On Sun, 11 May 2008 06:46:13 +0200, wongtd <wongtd smm.com> wrote:

 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 =3D new  =
 Composite(parent,DWT.SINGLE);     box.setSize(700,40);     auto No =3D=
new =
 Text(box,DWT.LEFT);     No.setBounds(1,15,10,15);      =
 No.setText("");            auto Date =3D new Text(box,DWT.LEFT);      =
 Date.setBounds( 21, 15, 60, 15);     Date.setText("");            auto=
=
 Content   =3D new Text(box,DWT.LEFT);     Content.setBounds( 90, 15,70=
, =
 15);     Content.setText("");     box.setVisible =3D true;      =
 controls["No"] =3D No;     controls["Date"] =3D Date;      =
 controls["Content"] =3D Content;           =
 box.setTabList(controls.values);   }   void setText(char[] name, char[=
] =
 text)   {       controls[name].setText(text);    } } void main () {   =
=
 Display display =3D new Display ();   Shell shell =3D new Shell (displ=
ay); =
 shell.setText("Boxes");      Box mybox1 =3D new Box(shell,DWT.SINGLE);=
=
 mybox1.setText("No","wire");   Box mybox2 =3D 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 befo=
re =
 (), not 1 of type int */

 I play with and put in

 }

   void setText(char[] text)
 {
   setText(text);//dont understand why this does not cause infinite loo=
p?
 }

   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) n=
ot =
 cause infinit loop?
 It calls itself seems so
 I tried to put in 'override' but would not compile
*wall of text crits for real.inf* Someone might be more positive to helping you if the code were somewhat = = formatted. I'd recommend adding the occasional line break. -- Simen
May 11 2008
prev sibling parent reply Ary Borenszweig <ary esperanto.org.ar> writes:
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).
May 11 2008
parent reply wongtd <wongtd smm.com> writes:
Ary Borenszweig Wrote:

 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).
Ok file posted too but did not show only pasted contents direct here. setText(name text) calls (invokes) setText(text) which is method of Text. Box creates many Text objects , each has a setText(text) method . Notice setText(text) calls itself ?
May 11 2008
parent reply Ary Borenszweig <ary esperanto.org.ar> writes:
wongtd escribió:
 Ary Borenszweig Wrote:
 
 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 Displa
y
 ();   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).
Ok file posted too but did not show only pasted contents direct here. setText(name text) calls (invokes) setText(text) which is method of Text. Box creates many Text objects , each has a setText(text) method . Notice setText(text) calls itself ?
Could you please point where in the pasted code is that call? I can't see it. I can see it, thought, separated from the rest of the code (after you wrote "I play with and put in"). Can you paste the modified main method, then?
May 12 2008
parent reply rewot yt ton <rewot yt.ton> writes:
Ary Borenszweig Wrote:
 Could you please point where in the pasted code is that call? I can't 
 see it. I can see it, thought, separated from the rest of the code 
 (after you wrote "I play with and put in"). Can you paste the modified 
 main method, then?
Why answer to Ty Tower idiot at all?
May 12 2008
next sibling parent Ary Borenszweig <ary esperanto.org.ar> writes:
rewot yt ton wrote:
 Ary Borenszweig Wrote:
 Could you please point where in the pasted code is that call? I can't 
 see it. I can see it, thought, separated from the rest of the code 
 (after you wrote "I play with and put in"). Can you paste the modified 
 main method, then?
Why answer to Ty Tower idiot at all?
Aah... I didn't know it was Ty Tower. But maybe you are right because of the extra spaces before dots and commas... Whether you are Ty Tower or not, I'd recommend you to read some OOP book or tutorial.
May 12 2008
prev sibling parent wongtd <wongtd smm.com> writes:
rewot yt ton Wrote:

 Ary Borenszweig Wrote:
 Could you please point where in the pasted code is that call? I can't 
 see it. I can see it, thought, separated from the rest of the code 
 (after you wrote "I play with and put in"). Can you paste the modified 
 main method, then?
Why answer to Ty Tower idiot at all?
seem Confusious had a toerag - it still around but at least post more than one word this time . Pity you not in earthquake
May 13 2008