Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
AddObject/RemoveObject
Message
 
To
22/03/2002 12:04:34
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00635975
Message ID:
00636213
Views:
19
>Hilmar's method of using AddObject DOES work correctly, without need to clean up yourself. VfP unfortunately modifies the names of the objects it adds to the form, so the RemoveObject does not find them again - but they are still in the Controls array & are correctly cleaned up on releasing the form.

Len,

I still would not recommend using the array stuff. For one reason it doesn;t provide any benefit, the form has a controls collection so the array doesn't add anything.

The main reason I wouldn't recommend it is that AddObject wants the object name as the first argument and using teh "thisform.array(x)" causes there to be multiple controls all with the same name. Try the code below and you can see what I mean.
DEFINE CLASS form1 AS form

   Top = 0
   Left = 0
   Height = 350
   Width = 582
   DoCreate = .T.
   Caption = "Form1"
   KeyPreview = .T.
   txtvalue = ""
   Name = "Form1"
   otest = .F.
   DIMENSION array[1,1]


   ADD OBJECT edit1 AS editbox WITH ;
      Height = 106, ;
      Left = 141, ;
      Top = 204, ;
      Width = 219, ;
      Name = "Edit1"


   ADD OBJECT label1 AS label WITH ;
      Caption = "Label1", ;
      Height = 17, ;
      Left = 32, ;
      Top = 149, ;
      Width = 40, ;
      Name = "Label1"


   ADD OBJECT command1 AS commandbutton WITH ;
      Top = 236, ;
      Left = 424, ;
      Height = 27, ;
      Width = 84, ;
      Caption = "Command1", ;
      Name = "Command1"


   PROCEDURE Init
      WITH Thisform
         DIMENSION Thisform.array(2)
         .AddObject("thisform.array(1)","label")
         .AddObject("thisform.array(2)","label")
         .array(1).Visible = .T.
         .array(2).top= 20
         .array(2).visible = .t.
         .edit1.value = "1st array label name: " + .array(1).name + CHR(13) + CHR(10) + ;
                        "2nd array label name: " + .array(2).name + CHR(13) + CHR(10) + ;
                        "Normal label name: " + .Label1.name
      ENDWITH
   ENDPROC


   PROCEDURE command1.Click
      Thisform.RemoveObject("array")
   ENDPROC


ENDDEFINE
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform