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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem creating EXE com server from a prg file

Status
Not open for further replies.

chriscboy

Programmer
Apr 23, 2002
150
GB
I have developed a small progress bar class that I want to create as a separate process, to ensure the animation still works when carrying out intensive database tasks. Unfortunately it is not working. The class prg is detailed below. If you copy and paste it as a prg and run it, you will see the progress bar running.

However if you add 'OLEPUBLIC' to the class definition, add it to a project, compile it as an EXE, and then try creating an instance using CreateObject("MyEXE.msgclass") (where MyEXE is the name of the compiled project), you will notice that nothing happens.

Have I missed something out, as the class works fine as a prg, but not a EXE.

Thanks in advance

Chris

Here comes the code;
Code:
Public otest
otest = CreateObject("msgclass")
otest.start("hello!")

DEFINE CLASS msgclass AS form && OLEPUBLIC

	Height = 90
	Width = 277
	DoCreate = .T.
	AutoCenter = .T.
	BorderStyle = 2
	Visible = .F.
	TitleBar = 0
	WindowType = 0
	AlwaysOnTop = .T.
	*-- Contains the file name of the avi video to run
	avifilename = "c:\work\vfp\ems\multimedia\filemove.avi"
	Name = "message"


	ADD OBJECT lblmessage AS label WITH ;
		Alignment = 0, ;
		Caption = "lblMessage", ;
		Height = 17, ;
		Left = 0, ;
		Top = 59, ;
		Width = 274, ;
		Name = "lblMessage"


	ADD OBJECT vcr AS olecontrol WITH ;
		Top = 0, ;
		Left = 0, ;
		Height = 61, ;
		Width = 276, ;
		Name = "VCR", ;
		OleClass = "MSComCtl2.Animation.2"


	ADD OBJECT progressbar AS olecontrol WITH ;
		Top = 76, ;
		Left = 0, ;
		Height = 14, ;
		Width = 276, ;
		Visible = .F., ;
		Name = "ProgressBar", ;
		OleClass = "MSComctlLib.ProgCtrl.2"

	*-- This shows the form and runs the avi
	PROCEDURE start
		********************************************************************
		* Name:					MESSAGE.START()
		* Description:			Shows the form and runs the AVI video
		* Author:				Chris Crowhurst
		* Date:					28/09/2005
		* Revision history:
		* {Date}		{Programmer}	{Version}		{Comments}
		* 28/09/2005	CMC				7.06.01			First Version
		* Inputs:		none
		* Outputs:		none
		********************************************************************
		Parameters tcMessage As Character

		* Display message if required
		If Type("tcMessage")="C"
			Thisform.lblMessage.Caption = tcMessage
		Else
			* No message so hide it
			Thisform.lblMessage.Visible = .F.
		EndIf

		* Show the form 
		ThisForm.Show()

		* Play the avi
		This.Playvideo()

		* Wait for very small keypress, this allows the AVI to play when 
		* launched from other forms
		Inkey(0.01,"HM")
	ENDPROC


	*-- This method stops the video and releases the form
	PROCEDURE stop
		********************************************************************
		* Name:					MESSAGE.STOP()
		* Description:			Stops the avi file and releases this form
		* Author:				Chris Crowhurst
		* Date:					28/09/2005
		* Revision history:
		* {Date}		{Programmer}	{Version}		{Comments}
		* 28/09/2005	CMC				7.06.00			First Version
		* Inputs:		none
		* Outputs:		none
		********************************************************************
		ThisForm.VCR.Stop()
		ThisForm.Release
	ENDPROC


	PROCEDURE avifilename_assign
		LPARAMETERS vNewVal
		*To do: Modify this routine for the Assign method
		THIS.avifilename = m.vNewVal
		This.Playvideo()
	ENDPROC


	*-- Plays the avi video file
	PROCEDURE playvideo
		********************************************************************
		* Name:					MESSAGE.PLAYVIDEO
		* Description:			Plays the avi file specified in property avifilename
		* Author:				Chris Crowhurst
		* Date:					28/09/2005
		* Revision history:
		* {Date}		{Programmer}	{Version}		{Comments}
		* 28/09/2005	CMC				7.06.01			First Version
		* Inputs:
		* Outputs:
		********************************************************************

		If Not Empty(Thisform.avifilename)
			ThisForm.VCR.Stop
			ThisForm.VCR.Open(Thisform.avifilename)
			ThisForm.VCR.Play
		EndIf
	ENDPROC


	*-- Displays a progress bar on the message window.
	PROCEDURE showprogress
		********************************************************************
		* Name:					MESSAGE.SHOWPROGRESS
		* Description:			Displays a progress bar on the window
		* 					    based on the parameters passed
		* Author:				Chris Crowhurst
		* Date:					28/09/2005
		* Revision history:
		* {Date}		{Programmer}	{Version}		{Comments}
		* 28/09/2005	CMC				7.06.01			First Version
		* Inputs:		tnCount - Current number or percentage if on tnCount is passed
		* 				tnMax	- Max number of items on progress bar
		* Outputs:
		********************************************************************
		LParameters tnCount,tnMax

		This.ProgressBar.Min = 1

		DO Case
			* Show N of M 
		 	Case Type("tnCount")="N" And Type("tnMax")="N"	 
				This.ProgressBar.Max = tnMax
				DO Case
					Case tnCount < 1
						This.ProgressBar.Value = 1
					Case tnCount > tnMax
						This.ProgressBar.Value = tnMax
					Otherwise
						This.ProgressBar.Value = tnCount
				EndCase
				This.ProgressBar.Visible = .T.
			* Show a percentage
			Case Type("tnCount")="N" And Type("tnMax")<>"N"
				This.ProgressBar.Max = 100
				DO Case
					Case tnCount < 1
						This.ProgressBar.Value = 1
					Case tnCount > 100
						This.ProgressBar.Value = 100
					Otherwise
						This.ProgressBar.Value = tnCount
				EndCase
				This.ProgressBar.Visible = .T.
		EndCase
	ENDPROC


	PROCEDURE Refresh
		Thisform.VCR.Refresh
	ENDPROC


	PROCEDURE Resize
		*!*	With Thisform.VCR
		*!*		.Height = ThisForm.Height - Thisform.lblMessage.Height - 5	 
		*!*		.Width = ThisForm.Width - 4
		*!*		.Refresh
		*!*	EndWith
		Thisform.VCR.Refresh
	ENDPROC


	PROCEDURE Init
		********************************************************************
		* Name:					MESSAGE.INIT
		* Description:			Initialises form and video controls
		* Author:				Chris Crowhurst
		* Date:					28/09/2005
		* Revision history:
		* {Date}		{Programmer}	{Version}		{Comments}
		* 28/09/2005	CMC				7.06.01			First Version
		* Inputs:		none
		* Outputs:		none
		********************************************************************

		* Check to see if OCX IS installed and loaded.
		If Type("THIS.VCR") # "O" Or Isnull(This.VCR)
			Return .F.
		EndIf

		_VFP.AutoYield = .F.
	ENDPROC


	PROCEDURE Destroy
		_VFP.AutoYield = .T.
	ENDPROC


ENDDEFINE
*
*-- EndDefine: message
**************************************************
 

Chris,

Don't forget that, when you launch a form via CREATEOBJECT(), it will be invisible until you explicitly make it visible.

You might try adding oTest.Visible = .t. immediately after the CREATEOBJECT().

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Mike,
I've just tried that, but unfortunately it has not made a difference.

Thanks

Chris
 
Chris

Why would you want to use a COM for something that should be a regular executable (with interface). COMs are mostly used from business rules and functions where interfaces are not required.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike Gagnon,

I had originally created this class as a visual class. It worked fine until I started calling the class from other forms in my project. Sometimes what would happen is that the message class would display and show the custom message, but would not play the avi file for some reason.

I searched TT and found this thread which showed how to create a progress bar as an out-of-process exe. So I tried this method. This time no UI appeared at all!!

I then tried including my class definition (as above) in my project as a prg, without using OLEPUBLIC, and now it works fine! I don’t get it. The prg class is exactly the same as the visual class except that in my code (that I copy & pasted from the class browser) I had to add the OleClass property to specify the active-x controls being used.

Its working fine now but ideally I would like to still use the visual class for further improvements in the future. At the moment I have a visual and prg class to maintain, which is not ideal, but it works. Does any one have any ideas as to why the avi does not display properly some times when using the VCX?
 

I noticed a slight difference between Craig's code and yours, in his code his form is not set to visible = .F. in the definition of the class and yours is. Have you tried removing that reference and also adding a otest.visible = .t. after the createobject() and perhaps a oTest.show(1) or 0 as other options?

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Mike,

Thanks. I have just tried that but to no avail. I don't know what else to try for the moment, so I think I will have to maintain the prg class. I have got a billion other things to do at the moment so can't spent too much time on this. At least it is working in one form though!

Still it would be interesting to understand why this not happening, but I think I will leave that for later.

Cheers
 
Hi Chris,

hehe, you forgot one essential thing: An out of process EXE com server has it's own _screen. Not only the form is invisible if created by CREATEOBJECT(), but also the _screen.

If you put the line _screen.visible = .T. inside your start()-procedure before ThisForm.Show(), you'll see. (Don't forget to recompile the Comserver).

Looks ugly though, doesn't it? So set Form.ShowWindow = 2 (as top level form) instead, that works and leaves the second screen invisible. But unfortunately TitleBar = 0 has no effect on top level forms. You should at least also set ControlBox = .f. to only have a pure titlebar.

Another disadvantege is, that the top level message form will be displayed within the task bar.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top