Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateObject Question

Status
Not open for further replies.

APS

Vendor
Sep 25, 2000
53
US
Hi

I am using CreateObject to create a form. Everything runs fine except when I try and include Screen=OFF in my config.fpw to get rid of the main VFP screen and then my form flashes on the screen. When I try and set the .showwindow=2 it tells me that is read only at runtime.
I have been able to do this in the past when designing a form but this is the first time using createobject.
Below is part of the code.

Myfrm = CreateObject("Form")
Myfrm.ALWAYSONTOP = .F.
Myfrm.AutoCenter=.T.
Myfrm.WindowType = 1
Myfrm.Height = 180
Myfrm.Width = 300

Thanks for the help!
Anthony


 
The show window property should be set at runtime or in the init event of the form (class).

The flash could be that you haven't issued a READ EVENTS ??
or .. try issuing a MyForm.Show() to show the form. The form is there but is invisible.

HTH,
Weedz (Wietze Veld)
veld4663@exact.nl

They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best.

After the GoldRush - Steve McConnell
 
Sorry...small error in typing... the show window property should of course be set at design time or in the init event of the form.

HTH,
Weedz (Wietze Veld)
veld4663@exact.nl

They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best.

After the GoldRush - Steve McConnell
 
Hi APS,

When you use CREATEOBJECT the rules of Object Oriented programming take effect. THis means that FoxPro has defined some properties on a object (form) that are only available at design time and cannot be changed during the excistence or visibility of an object.

In your case I would try to create the window default invisible and then change the showwindow property to 2 and then make the window visible.

The following code should do the trick:

Myfrm = CreateObject("Form")
Myfrm.Visible = .F.
Myfrm.ALWAYSONTOP = .F.
Myfrm.AutoCenter=.T.
Myfrm.WindowType = 1
Myfrm.Height = 180
Myfrm.Width = 300

Myfrm.showwindow=2
Myfrm.Visible = .T.

If this doesn't work the property can never be changed during runtime only at design time.


JNC73
 
After checking, the reason why your form flashes is that it looses scope. Since the object you create is a variable reference and your variable is by default a PRIVATE when not declared, it is destroyed as soon as your procedure is left.

If you make you form PUBLIC (which is indeed not a good practice..in most cases), you can see that it does not flash.

But...the good thing is...you have just entered the beautiful world of OOP in VFP.

HTH,

Weedz (Wietze Veld)
veld4663@exact.nl

They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best.

After the GoldRush - Steve McConnell
 
I do issue the read event and show commands. Here is the rest of the code. It works fine as long as I let the main vfp window popup as soon as I create a config.fpw with screen=off in it my form does not display. Thanks again for the help!

oPB = CreateObject("Form")
oPB.ALWAYSONTOP = .F.
oPB.AutoCenter=.T.
oPB.WindowType = 1
oPB.Height = 180
oPB.Width = 300

oPB.ADDOBJECT("Text1","Text1")
oPB.ADDOBJECT("Text2","Text2")
oPB.ADDOBJECT("Period","period")
oPB.ADDOBJECT("Year","Year")
oPB.ADDOBJECT("Completed","Completed")
oPB.ADDOBJECT("Progress1","Progress1")
oPB.ADDOBJECT("oCmd1","oCmd1")
oPB.ADDOBJECT("oCmd2","oCmd2")
oPB.ADDOBJECT("oCmd3","oCmd3")

oPB.ocmd1.Visible = .T.
oPB.ocmd2.Visible = .T.
oPB.ocmd3.Visible = .T.
oPB.Text1.Visible = .T.
oPB.Text2.Visible = .T.
oPB.Period.Visible = .T.
oPB.Year.Visible = .T.
oPB.ocmd3.Visible = .T.

oPB.SHOW()
Read Events

Define Class Text1 AS TextBox
HEIGHT = 24
LEFT =100
WIDTH = 100
ALIGNMENT = 0
InputMask = "XX"
TOP = 25
BACKCOLOR = RGB(255,255,255)
ControlSource = 'cPeriod'
DISABLEDBACKCOLOR = RGB(255,255,255)
DISABLEDFORECOLOR = RGB(0,0,0)
ENABLED = .T.
FONTBOLD = .F.
DateFormat = 1
enddefine
Define Class Text2 as textbox
HEIGHT = 24
LEFT =100
WIDTH = 100
ALIGNMENT = 0
InputMask = "XXXX"
TOP = 50
BACKCOLOR = RGB(255,255,255)
ControlSource = 'cYear'
DISABLEDBACKCOLOR = RGB(255,255,255)
DISABLEDFORECOLOR = RGB(0,0,0)
ENABLED = .T.
FONTBOLD = .F.
DateFormat = 1
enddefine
Define Class Period AS Label
HEIGHT = 17
LEFT =60
WIDTH = 35
ALIGNMENT = 0
TOP = 32
DISABLEDBACKCOLOR = RGB(192,192,192)
DISABLEDFORECOLOR = RGB(0,0,0)
ENABLED = .F.
FONTBOLD = .T.
enddefine
Define Class Year AS Label
HEIGHT = 17
LEFT =73
WIDTH = 28
ALIGNMENT = 0
TOP = 58
DISABLEDBACKCOLOR = RGB(192,192,192)
DISABLEDFORECOLOR = RGB(0,0,0)
ENABLED = .F.
FONTBOLD = .T.
enddefine
Define Class Completed AS Label
HEIGHT = 17
LEFT =115
WIDTH = 100
ALIGNMENT = 0
TOP = 83
DISABLEDBACKCOLOR = RGB(192,192,192)
DISABLEDFORECOLOR = RGB(0,0,0)
ENABLED = .F.
FONTBOLD = .T.
enddefine
Define Class Progress1 AS progreso
HEIGHT = 24
LEFT =50
WIDTH = 197
TOP=100
enddefine
Define Class oCmd1 AS COMMANDBUTTON
CAPTION = &quot;\<Process&quot;
HEIGHT = 25
LEFT = 3
WIDTH = 97
TOP = 150
PROCEDURE CLICK
Do CustLink
Do Arlink
ENDPROC
enddefine
Define Class oCmd2 AS COMMANDBUTTON
CAPTION = &quot;\<Quit&quot;
HEIGHT = 25
LEFT = 102
WIDTH = 97
TOP = 150
PROCEDURE CLICK
Clear Events
ENDPROC
enddefine
Define Class oCmd3 AS COMMANDBUTTON
CAPTION = &quot;\<Print&quot;
HEIGHT = 25
LEFT = 201
WIDTH = 97
TOP = 150
PROCEDURE CLICK
DO ReportWindow
ENDPROC
ENDDEFINE
 
Sorry

The oPB.Show() should be oPB.SHOW(2)

Thanks
Anthony
 
The best thing you can do is define a class as form and in the class definition you should set the show window property to 2.

It is a good practice not to use the VFP base classes directly but to subclass them first as your own base class.

DEFINE CLASS myForm AS FORM
ShowWindow = 2
ENDDEFINE

Your form is shown as Modeless - oPB.SHOW(2). (the 2 indicates that it is modeless where 1 indicates modal)

The variable you are using, is it a public or a private? If it is private (or local for that matter), the answer about the flash and going out of scope stands.

In your code, your form is still not a top level form of ShowWindow = 2.

I suggest you try making your form (oPB) public and using a form class definition as described here.

If you do that your form will show properly.

HTH,

Weedz (Wietze Veld)
veld4663@exact.nl

They cling emotionally to code and fix development rather than choosing practices based on analytical assesments of what works best.

After the GoldRush - Steve McConnell
 
Thanks for the help. Using the define class worked!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top