[Gambas-user] Re: making objects of a class in a loop

Toni Schornboeck toni at ...706...
Tue Jan 4 12:26:05 CET 2005


> is there something like:
>  PUBLIC SUB _new(nb AS Integer)
>   i AS Integer
>   arFrage AS Object[]
>   for i = 0 to nb-1
>    ClFrage fr_i = NEW ClFrage
>    arFrage.add(fr_i)
>   next
>  END

What about this? 

private fragen as Object[] 

public sub _new(n as integer)
 dim i as integer
 dim temp as ClFrage 

 fragen = new Object[]
 for i=0 to n-1
   temp=new ClFrage
   fragen.add(temp)
 next
end 

unfortunately you can't write
fragen.add(new ClFrage)
so i often write a static public function make() within ClFrage which 
constructs an object and works like the normal constructor (takes the same 
arguments, etc.). so one can write:
fragen.add(ClFrage.make()) 





More information about the User mailing list