[Gambas-user] Re: Re: Trying to create a form and add controls dynamically

R Onstenk ronstk at ...239...
Sun Sep 28 13:41:56 CEST 2003


A quetion about the same

I have a form and two classes as FMain, Cframes and Cframe.
I show here the relevant code only, Cframe can be 0 to n instances
under program control and are connected with lines between them.  
 
Cframe has events for handling by the manager Cframes and events
to handle by the main program.
-------------
Cframe:
sub _new(parent as object)
  inc findex	
  hP = parent
  hF = new Frame(p) as "fr"
  hF.tag =	findex 
  hL = new ListBox(f) as "lb"		
  hB = New Button(f) as "btn"	
end

fr_click()
  raise frclick(hF) ' raise event to Cframes

lb_click()
  raise lbclick(hL) ' raise event to Cframes
-------------
Cframes:
sub Add(parent as object)
  obj = new Cframe(parent as object) as "cf"
  obj.move(x,y,w,h)	
  pcollection.add(obj, obj.tag) ' add to collection
  etc.
end

sub Remove(obj as object)
  'obj.tag is id of the Frame
  dim o as object
  dim key as sting
  key = obj.tag
  for each o in obj.children
    o.delete ' button and listbox
  next
  obj.delete		
  pcollection.remove(key)	
end

cf_frclick(hF as object)
  'tag is id of the frame
  'do some the actions for the frame hF
end

cf_lbclick(hL as object) 
  'tag is id of the frame
  RAISE lbisClicked(hL)	 'cant handle this
end
--------------
FMain:
sub _New  
  hCFr = NEW Cframes(Fmain) as "CFR"
end

sub CFR_lbisClicked(hL as object) 'raised be CFrames
  'tag is id of the frame
  'never comes here
end  

sub CleanUp()
  dim o as object
  for each o in me.children
    if object.type(o) = "Frame" then CFR.Remove(o.tag)
  next
end
--------------

4 questions:
1)
In both 'for each' loops the last object is not deleted.
The last in .children stay's on the form for the loop in Fmain 'CleanUp()'.
All the other object are gone as expected.
Is this a bug? PRINT .Children.Count say's 1 after NEXT.

2)
If I have a container contol like a frame and put other controls on it
do I have to delete/remove theme before I delete the
container control or is this done automatic? (can't find info)

3)
Is it better to place the routine to delete the button and listbox
in the Cframe _free procedure? (it look to me it should be)

4)
When the Cframe raises a event that must be a event from Cframes
then I can raise the event in Cframes ( cf_lbclick() )but it never 
arives in the main program.
Can I raise nested events as here is the case?

BTW:
For the delete in de Cframes:
  hF.delete		
  pcollection.remove(id)	
The order does not matter but only if both are done then _free event 
in Cframe fires.

-----------
Greets Ron





More information about the User mailing list