[Gambas-user] Dynamic processes and killing them

Brian Snipes bsnipes at ...21...
Sat Jul 19 05:08:31 CEST 2003


I am trying to code a program that will let you insert a host or ip to
ping and show the results as items in a listbox.  A process is spawned
everytime a host is inserted in a text box and the insert button is
clicked on.  There is also a delete button that I want to remove the
list item and kill the process that goes along with that item.  I can't
seem to figure out how to determine how to remove this process.  Here is
the class code so far and I know it needs help since there are several
concepts in Gambas I haven't grasped.  Any hints toward a solution would
be appreciated.

' Gambas class file
PRIVATE myProcess AS Process
PUBLIC myPid AS Integer

PUBLIC SUB Form_Open()

END

PUBLIC SUB btnInsert_Click()

  ' insert ping into list
  IF (txtInsert.text) THEN
    IF NOT (lvwPingList.exist(txtInsert.text)) THEN        
        EXEC ["ping", txtInsert.text] FOR READ AS myProcess
        lvwPingList.add(myProcess.id, txtInsert.text) 
    ENDIF
  ENDIF    
END

PUBLIC SUB btnDelete_Click()
  IF lvwPingList.item THEN  
    IF lvwPingList.item.selected  THEN
      myPid = lvwPingList.current.key
      TRY Process.kill(myPid)
      lvwPingList.remove(lvwPingList.current.key)
    ENDIF
  ENDIF
  
END

PUBLIC SUB btnExit_Click()

  ME.close
  
END

'------------------------------------------------ 
 ' if something is coming back 
 ' the event 'Process.Write' of the class process calls this function 
PUBLIC SUB Process_Write(sData AS String)
  lvwPingList[LAST.id].text=Left$(sData, -1)  
END

Brian






More information about the User mailing list