Sorry -not getting anywhere with setText()

Ary Borenszweig ary at esperanto.org.ar
Thu May 8 06:27:06 PDT 2008


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


More information about the Digitalmars-d-learn mailing list