www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Sorry -not getting anywhere with setText()

reply June <somewhere so.com> writes:
Content-Type: text/plain

Attach what I am trying to make work -not winning here ,round and round in loops
Any help appreciated
May 07 2008
next sibling parent reply Max Samukha <nospam nospam.com> writes:
On Thu, 08 May 2008 02:26:27 -0400, June <somewhere so.com> wrote:

Attach what I am trying to make work -not winning here ,round and round in loops
Any help appreciated

You defined the setText(char[] name, char[] text) as nested function in Box's constructor. Move it out to the class' scope. Btw, 'public:' is not needed as class members are public by default.
May 08 2008
parent reply Max Samukha <nospam nospam.com> writes:
On Thu, 08 May 2008 10:36:20 +0300, Max Samukha <nospam nospam.com>
wrote:

On Thu, 08 May 2008 02:26:27 -0400, June <somewhere so.com> wrote:

Attach what I am trying to make work -not winning here ,round and round in loops
Any help appreciated

You defined the setText(char[] name, char[] text) as nested function in Box's constructor. Move it out to the class' scope. Btw, 'public:' is not needed as class members are public by default.

The following may have typos but should demonstrate the idea described in the previous thread: 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 mybox = new Box(shell,DWT.SINGLE); mybox.setText("No","wire"); mybox.setText("Content","Fishingline"); shell.pack(); shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); }
May 08 2008
parent reply June <somewhere so.com> writes:
Content-Type: text/plain

Max Samukha Wrote:

 On Thu, 08 May 2008 10:36:20 +0300, Max Samukha <nospam nospam.com>
 wrote:
 
On Thu, 08 May 2008 02:26:27 -0400, June <somewhere so.com> wrote:

Attach what I am trying to make work -not winning here ,round and round in loops
Any help appreciated

You defined the setText(char[] name, char[] text) as nested function in Box's constructor. Move it out to the class' scope. Btw, 'public:' is not needed as class members are public by default.

The following may have typos but should demonstrate the idea described in the previous thread: 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 mybox = new Box(shell,DWT.SINGLE); mybox.setText("No","wire"); mybox.setText("Content","Fishingline"); shell.pack(); shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); }

May 08 2008
parent reply Max Samukha <nospam nospam.com> writes:
On Thu, 08 May 2008 04:35:18 -0400, June <somewhere so.com> wrote:

Max Samukha Wrote:

 On Thu, 08 May 2008 10:36:20 +0300, Max Samukha <nospam nospam.com>
 wrote:
 
On Thu, 08 May 2008 02:26:27 -0400, June <somewhere so.com> wrote:

Attach what I am trying to make work -not winning here ,round and round in loops
Any help appreciated

You defined the setText(char[] name, char[] text) as nested function in Box's constructor. Move it out to the class' scope. Btw, 'public:' is not needed as class members are public by default.

The following may have typos but should demonstrate the idea described in the previous thread: 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 mybox = new Box(shell,DWT.SINGLE); mybox.setText("No","wire"); mybox.setText("Content","Fishingline"); shell.pack(); shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); }


The attached file is empty
May 08 2008
parent reply June <somewhere so.com> writes:
Content-Type: text/plain

Max Samukha Wrote:

 On Thu, 08 May 2008 04:35:18 -0400, June <somewhere so.com> wrote:
 
Max Samukha Wrote:

 On Thu, 08 May 2008 10:36:20 +0300, Max Samukha <nospam nospam.com>
 wrote:
 
On Thu, 08 May 2008 02:26:27 -0400, June <somewhere so.com> wrote:

Attach what I am trying to make work -not winning here ,round and round in loops
Any help appreciated

You defined the setText(char[] name, char[] text) as nested function in Box's constructor. Move it out to the class' scope. Btw, 'public:' is not needed as class members are public by default.

The following may have typos but should demonstrate the idea described in the previous thread: 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 mybox = new Box(shell,DWT.SINGLE); mybox.setText("No","wire"); mybox.setText("Content","Fishingline"); shell.pack(); shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); }


The attached file is empty

May 08 2008
parent Max Samukha <nospam nospam.com> writes:
On Thu, 08 May 2008 05:53:22 -0400, June <somewhere so.com> wrote:

Max Samukha Wrote:

 On Thu, 08 May 2008 04:35:18 -0400, June <somewhere so.com> wrote:
 
Max Samukha Wrote:

 On Thu, 08 May 2008 10:36:20 +0300, Max Samukha <nospam nospam.com>
 wrote:
 
On Thu, 08 May 2008 02:26:27 -0400, June <somewhere so.com> wrote:

Attach what I am trying to make work -not winning here ,round and round in loops
Any help appreciated

You defined the setText(char[] name, char[] text) as nested function in Box's constructor. Move it out to the class' scope. Btw, 'public:' is not needed as class members are public by default.

The following may have typos but should demonstrate the idea described in the previous thread: 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 mybox = new Box(shell,DWT.SINGLE); mybox.setText("No","wire"); mybox.setText("Content","Fishingline"); shell.pack(); shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); }


The attached file is empty


Unlike in .NET winforms, you cannot set text for any control and Control class does not have a setText property so if you don't plan to use other controls than Text, declare the value type of the associative array to be Text. Also I'm not sure that Composite has a setTabList property. Please consult SWT reference. And if I understand correctly you are going to use lots of textboxes. If you are going to present a list or tabular data, it would be better for performance and yourself to use a grid or list control whatever is appropriate and available in DWT.
May 08 2008
prev sibling parent Ary Borenszweig <ary esperanto.org.ar> writes:
June wrote:
 Attach what I am trying to make work -not winning here ,round and round in
loops
 Any help appreciated
 

Why are you storing Text instances in an associative array and then accessing them by name? You are doing: Box mybox = new Box(shell,DWT.SINGLE); mybox.setText("No","wire"); mybox.setText("Content","Fishingline"); Than means that you know that Box has a "No" and "Content" Text. I recommend you to store them as public fields of Box class (or as properties, it's almost the same): class Box { Text No; Text Date; Text Content; public: this (Composite parent ,int style ) { // ... No = new Text(box,DWT.LEFT); Date = new Text(box,DWT.LEFT); Content = new Text(box,DWT.LEFT); // ... } } That way, if you mistype "Content", "No" or "Date", you'll get a compile error, while in your approach, you'll get a runtime error. And also, if you use an IDE that offers autocompletion, you can do "box." and get No, Date and Content as suggestions. The setText method, in this case, should be: void setText(Text control, char[] text) { control.setText(text); }
May 08 2008