Hi Joe,
VFP isn't able to add an existing object to the form to be displayed.
It instantiates an object on the form with the AddObject or NewObject
commands.
When you add an object this way it will not display until you set the
Visible property.
I have two examples below.
Here is how that code could be written:
* Create a blank form
loMyForm = CREATEOBJECT("Form")
MESSAGEBOX("Form created successfully")
* Add the spotpick1 to the form
loMyForm.AddObject("SpotPick1", "spotpick1")
loMyForm.SpotPick1.Visible = .T.
* Show the form, in a Modal state
loMyForm.Show(1)
RETURN
DEFINE CLASS spotpick1 AS container
WIDTH = 100
PROCEDURE Init
* Add your custom logic here (e.g., create controls, set
properties)
THIS.AddControls()
ENDPROC
PROCEDURE AddControls
* Add a textbox to the container
THIS.AddObject("Textbox1", "TextBox")
THIS.Textbox1.Value = "Hello from TextBox 1"
THIS.TextBox1.Visible = .T.
* Add a second textbox to the container
THIS.AddObject("Textbox2", "TextBox")
THIS.Textbox2.Value = "Hello from TextBox 2"
THIS.TextBox2.Visible = .T.
THIS.Textbox2.Top = 30
ENDPROC
ENDDEFINE
Here is an example of defining the classes in a prg and using it in a form
class two ways
* Create class form
loMyForm = CREATEOBJECT("FormClass")
* Show the form
loMyForm.Show()
RETURN
* Define the customized container
DEFINE CLASS spotpick1 AS container
WIDTH = 200
ADD OBJECT Textbox1 as TextBox WITH Value = "Hello from TextBox 1",
Width = 200
ADD OBJECT Textbox2 as TextBox WITH Value = "Hello from TextBox 2",
Width = 200, Top = 30
ENDDEFINE
* define the customized form
DEFINE CLASS formclass as Form
WindowType = 1
ADD OBJECT spotpick1 as spotpick1
PROCEDURE init
This.AddSecondContainer()
ENDPROC
PROCEDURE AddSecondContainer
This.AddObject("spotpick2", "spotpick1")
This.spotpick2.top = 100
This.spotpick2.visible = .T.
ENDPROC
ENDDEFINE
HTH,
Tracy
-----Original Message-----
From: ProfoxTech [mailto:[email protected]] On Behalf Of Joe
Yoder
Sent: Wednesday, July 10, 2024 10:02 PM
To: [email protected]
Subject: Class code issue
I am developed a custom class based on a container that worked properly
when it was on a form but when I converted it to a class I have issues I
can't resolve. I have only one installation of VFP and sometimes I wonder
if it might be corrupt.
In order to avoid any corruption of the visual tools I have attempted to
come up with a small .prg program that creates a form, defines a custom
class in code, and puts an instance of the class on the form.
,The following code was written by Microsoft's CoPilot but the author has
not been able to make it work!
The problem seems to be that the definition code needs to reference the
class before it is instantiated.
* Create a blank form
loMyForm = CREATEOBJECT("Form")
MESSAGEBOX("Form created successfully")
* Create an instance of your spotpick1 class
loSpotPick1 = CREATEOBJECT("spotpick1")
MESSAGEBOX("Class created successfully")
* Add the spotpick1 to the form
loMyForm.AddObject("SpotPick1", loSpotPick1)
* Show the form
loMyForm.Show()
RETURN
DEFINE CLASS spotpick1 AS container
PROCEDURE Init
* Add your custom logic here (e.g., create controls, set properties)
THIS.AddControls()
ENDPROC
PROCEDURE AddControls
LOCAL oTextbox1, oTextbox2
oTextbox1 = CREATEOBJECT("TextBox")
oTextbox2 = CREATEOBJECT("TextBox")
oTextbox1.Value = "Hello from TextBox 1"
oTextbox2.Value = "Hello from TextBox 2"
THIS.AddObject("Textbox1", oTextbox1) && Errors here
THIS.AddObject("Textbox2", oTextbox2) && Errors here
ENDPROC
ENDDEFINE
Thanks in advance for any help!
Joe
--- StripMime Report -- processed MIME parts ---
multipart/alternative
text/plain (text body -- kept)
text/html
---
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/profox
OT-free version of this list: https://mail.leafe.com/mailman/listinfo/profoxtech
Searchable Archive: https://leafe.com/archives
This message:
https://leafe.com/archives/byMID/[email protected]
** All postings, unless explicitly stated otherwise, are the opinions of the
author, and do not constitute legal or medical advice. This statement is added
to the messages for those lawyers who are too stupid to see the obvious.