[Gambas-user] Delete an object

Almanova Sistemi almanova at ...1228...
Mon Apr 3 10:22:08 CEST 2006


Benoit Minisini ha scritto:

>On Saturday 01 April 2006 16:31, Almanova Sistemi wrote:
>  
>
>>I delete a text area (TextArea.Delete). The on-line help says: Note that
>>a destroyed control becomes an invalid object.
>>How can I delete an object whitout an invalid object as result?
>>
>>Thank's
>>
>>Massimo
>>
>>    
>>
>
>Why do you want to use something that does not exist anymore? :-)
>
>  
>
No, I don't want to use an object that not exist.
This is my problem:
I have a panel and I want add and/or delete some objetcts from them.
Now, the objects are stored in a collection and when I delete them from 
the panel, delete also from the collection.
When I insert (into the panel and into the collection) a new object 
(Text Area, Drawing Area etc.) and select them I get
an invalid object.

This is a fragment of code:

....
PRIVATE hForm AS Object
PRIVATE hBorder AS Integer
PRIVATE hTag AS String
PRIVATE Height AS Integer
PRIVATE Width AS Integer

PRIVATE hObj AS NEW Collection
....
*'--- this get the position of the object and activate the border*
PUBLIC SUB vForm_Enter()
  DIM iI AS Integer

  DIM Xa AS Integer
  DIM Xb AS Integer
  DIM Xc AS Integer
  DIM Xd AS Integer

  DIM Ya AS Integer
  DIM Yb AS Integer
  DIM Yc AS Integer
  DIM Yd AS Integer

  DIM W AS Integer
  DIM H AS Integer

  IF Selected THEN
    $MX = Mouse.ScreenX
    $MY = Mouse.ScreenY
    $X = LAST.X
    $Y = LAST.Y
    IF Right(hForm.Tag, 1) = "T" THEN
      hForm.ReadOnly = TRUE
    END IF
  END IF

  FOR iI = 1 TO hObj.Count
    MX = Mouse.ScreenX
    MY = Mouse.ScreenY

    W = hObj[iI].Width     '*<-- here I get Not an object*
    H = hObj[iI].Height

    Xa = hObj[iI].ScreenX
    Xb = Xa + W
    Xc = Xa
    Xd = Xb

    Ya = hObj[iI].ScreenY
    Yb = Ya
    Yc = Ya + H
    Yd = Yc

    IF Xa <= MX AND Xb >= MX AND Ya <= MY AND Yc >= MY THEN
      hForm = hObj[iI]
    END IF
  NEXT
  hBorder = hForm.Border
  hForm.Border = Border.Plain

END
....
*'--- this insert a new Text Area*
PUBLIC SUB Testo_Click()

  Unselect(hForm)
  hForm = NEW TextArea(pnaEtichetta) AS "vForm"
  hForm.Font.Name = cmbBoxFontName[cmbBoxFontName.Index].Text
  hForm.Font.Size = Val(cmbBoxFontSize[2].Text)
  hForm.X = 20
  hForm.Y = 10
  hForm.Visible = TRUE
  hForm.Enabled = TRUE
  hForm.Resize(pnaEtichetta.Width - 24, 24)
  Height = hForm.Height
  Stile()
  iI = iI + 1
  hForm.Tag = Str(iI) & "T"
  hObj.Add(hForm, iI)
  Select(hForm, TRUE)

END
....
'*--- this delete the object
*PUBLIC SUB hTaglia_Click()

  IF Left(hForm.Tag,1) ="S" THEN
    hObj.Remove(Mid(hForm.Tag, 2, 1))
    unselect(hForm)
    hForm.Delete
  END IF
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20060403/01c54ce9/attachment.html>


More information about the User mailing list