# ap-list:2701

require "phi" ; include Phi

form = Form.new :form , "dispose control"

button1 = Button.new form, :button1, "button1:make"
button2 = Button.new form, :button2, "button2:make"
button3 = Button.new form, :button3, "button3:make"
button4 = Button.new form, :button4, "button4:make"

button1.top = 00 ; button1.width = 100
button2.top = 30 ; button2.width = 100
button3.top = 60 ; button3.width = 100
button4.top = 90 ; button4.width = 100

control_no = 1
on_click = proc { |sender|
  if /(.*)(\d)(:)(dispose|make)/  =~ sender.caption
    if $4 == "make"
      edit = Edit.new form, "edit#{control_no}"
      control_no += 1
      edit.top = sender.top
      edit.left = 120
      sender.caption = $1+$2+$3+"dispose"
    else
      top = sender.top
      edits = form.controls.select{|c|(c.is_a? Edit) && (c.top == top)}
      edits.each{|e| 
        e.parent = nil   # <- This means dispose_control.
      }
      sender.caption = $1+$2+$3+"make"
    end
    puts "----",form.controls.select{|c|c.is_a? Edit}
  end
}

button1.on_click = on_click
button2.on_click = on_click
button3.on_click = on_click
button4.on_click = on_click

form.show ; mainloop
