For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > April 2006 > use ocx without a form?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author use ocx without a form?
mbosco51@hotmail.com

2006-04-25, 6:57 pm

Hi. I have a component that will allow me to access a Btrieve
database. I am going to use this component to insert records. This is
expected to be an unintended app, therefore I don't want to have a
form. Right now I have it working fine with the form, which is never
shown, but I'm wondering if I can somehow use the component without the
form? I tried referencing the object like so...

Set obj = CreateObject("ocx name.component name")

but I get "ActiveX component can't create object". I've read some
posts that say this may be possible depending on how the component is
written. So the problem may just be that my component doesn't support
this, but I'm wondering if maybe I'm just going about it the wrong way.

Any help would be greatly appreciated. Thanks.

Bob O`Bob

2006-04-25, 6:57 pm

mbosco51@hotmail.com wrote:
> Hi. I have a component that will allow me to access a Btrieve
> database. I am going to use this component to insert records. This is
> expected to be an unintended app,



Yeah, I get those sometimes too.


> therefore I don't want to have a
> form. Right now I have it working fine with the form, which is never
> shown, but I'm wondering if I can somehow use the component without the
> form? I tried referencing the object like so...
>
> Set obj = CreateObject("ocx name.component name")
>
> but I get "ActiveX component can't create object". I've read some
> posts that say this may be possible depending on how the component is
> written. So the problem may just be that my component doesn't support
> this, but I'm wondering if maybe I'm just going about it the wrong way.
>
> Any help would be greatly appreciated. Thanks.
>



A form is just a class.
It also happens to have a UI, but that does not force you to ever show it.

I use never-shown forms fairly frequently, when I choose to host a control
(e.g. Winsock) because it's just *easy* to do - and that's a big part of
what VB is [was] about.

Odds are, there is some way to do what you want without a form.
Odds also are that it's far, far more trouble to do than it could ever save you.



Bob
--
MikeD

2006-04-25, 6:57 pm


<mbosco51@hotmail.com> wrote in message
news:1145998246.523001.299800@u72g2000cwu.googlegroups.com...
> Hi. I have a component that will allow me to access a Btrieve
> database. I am going to use this component to insert records. This is
> expected to be an unintended app, therefore I don't want to have a
> form. Right now I have it working fine with the form, which is never
> shown, but I'm wondering if I can somehow use the component without the
> form? I tried referencing the object like so...
>
> Set obj = CreateObject("ocx name.component name")
>
> but I get "ActiveX component can't create object". I've read some
> posts that say this may be possible depending on how the component is
> written. So the problem may just be that my component doesn't support
> this, but I'm wondering if maybe I'm just going about it the wrong way.



I wouldn't recommend this. Just continue to use a "no-show form". The
problem is that controls are designed to be sited in some kind of container.
Even if you can instantiate it using CreateObject, it's likely to not behave
correctly. For example, most controls "inherit" certain property values from
its container or rely on its container for other things. It can only do this
if it's properly sited, so if it's not sited, it can result in unexpected
results, or instability, or even worse.

The best thing you can do is keep things as they are and use the form to
"host" the control.


--
Mike
Microsoft MVP Visual Basic

Dick Grier

2006-04-25, 9:56 pm

Mike and Bob are "on target."

Just use the Form, with the Visible property = False. Too often (IMO) a
late-bound control will do something unexpected.

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.


mbosco51@hotmail.com

2006-04-26, 7:56 am

Ok, I'll keep it the way it is then. Thanks guys!

Karl E. Peterson

2006-04-26, 6:56 pm

mbosco51@hotmail.com wrote:
> Hi. I have a component that will allow me to access a Btrieve
> database. I am going to use this component to insert records. This
> is expected to be an unintended app, therefore I don't want to have a
> form. ^^^^^^^^^^


Although I liked Bob's twist on this <g>, I assume you meant to say
*unattended* app, right? And in those, you cannot have a UI. Period. Even
if never shown. Am I on target?

> Right now I have it working fine with the form, which is never
> shown, but I'm wondering if I can somehow use the component without
> the form? I tried referencing the object like so...
>
> Set obj = CreateObject("ocx name.component name")


Do you control the source of this beast? If so, VB6 can produce OCXs that
expose public classes as well as controls. Rather than drag the OCX into
your toolbox, set a reference to it in Project-References.

Even if you don't control the source, it's possible the original author
provided a similar means to it that way. After setting the reference, in
that case, check the Object Browser to see what's available to you.

> but I get "ActiveX component can't create object". I've read some
> posts that say this may be possible depending on how the component is
> written. So the problem may just be that my component doesn't support
> this, but I'm wondering if maybe I'm just going about it the wrong
> way.


Hard to know without having the component in hand. Best bet, contact the
creator.
--
Working without a .NET?
http://classicvb.org/


Dick Grier

2006-04-26, 6:56 pm

Hi Karl,

Define "unattended" app. Do you mean a Service? If so, then of course, you
are right. But, "unattended" doesn't imply a Service, though it might me
implemented as one.

To me, "unattended" means that it starts automatically when the PC starts,
and ends when the PC shuts down.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.


Karl E. Peterson

2006-04-26, 6:56 pm

Hi Dick --

> Define "unattended" app.


Project->Properties->General...

=====================================
Setting Unattended Execution

Unattended Execution allows you to create components that can run without
operator intervention on network servers. Selecting Unattended Execution
doesn't affect the threading model of your component.

To mark your ActiveX DLL or EXE project for unattended execution

1. On the Project menu, click <project> Properties to open the Project
Properties dialog box.

2. On the General tab, check Unattended Execution, then click OK.

Important Selecting the Unattended Execution option suppresses all forms
of user interaction — including message boxes and system error dialogs. This
is discussed in "Event Logging for Multithreaded Components."
-------------------------------------
http://msdn.microsoft.com/library/e...r /> lbasic.asp
=====================================

And:

=====================================
*NOTE: The Unattended Execution option is not available if the project
contains any user interface elements, such as forms or controls. The Retain
In Memory option is not available if Unattended Execution is not selected.
-------------------------------------
PRB: Threading Issues with Visual Basic 6.0 ActiveX Components
http://support.microsoft.com/kb/241896/
=====================================

More reading:
http://www.google.com/search? q=%22...br /> osoft.com

> Do you mean a Service? If so, then of
> course, you are right. But, "unattended" doesn't imply a Service,
> though it might me implemented as one.


No, not a service, but an application that's designed to run on a server
(presumably under IIS).

> To me, "unattended" means that it starts automatically when the PC
> starts, and ends when the PC shuts down.


You don't do the foof, though... ;-)
--
Working without a .NET?
http://classicvb.org/


Dick Grier

2006-04-27, 6:56 pm

Hi Karl,

OK, now I understand. I never had any reason to go that route, though the
system error dialog suppression is a "good thing."

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.


Karl E. Peterson

2006-04-27, 6:56 pm

Dick Grier wrote:
> OK, now I understand. I never had any reason to go that route,
> though the system error dialog suppression is a "good thing."


Yeah, I hadn't until recently, myself. Wondered why folks wanted me to
remove the About box in ccrpTimers, way back when. Now I know.
--
Working without a .NET?
http://classicvb.org/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com