Converting DLL code to OCX???

I have a DLL that I made with Delphi7 Pro 4 years ago.
Now a client needs it but he wants to use it as an ActiveX component instead of a plain dll...

Is there a _simple_ way to re-cast my code to become an OCX?

--
Bo Berglund
0
Bo
11/10/2009 10:44:39 AM
embarcadero.delphi.win32 2183 articles. 0 followers. Follow

7 Replies
735 Views

Similar Articles

[PageSpeed] 40
Get it on Google Play
Get it on Apple App Store

<Bo Berglund> wrote in message news:181715@forums.codegear.com...
>
> Is there a _simple_ way to re-cast my code to become an OCX?

If your DLL is mainly a number of classes, then yes. You can make sure they 
inherit from TCustomControl and the built-in wizard can turn them into an 
OCX object. There are of course a few more steps to make it work, but it is 
fairly simple (at least the second time....)

If your DLL does something completely different, well then ??
0
Uffe
11/10/2009 1:25:37 PM
> {quote:title=Uffe Kousgaard wrote:}{quote}
> <Bo Berglund> wrote in message news:181715@forums.codegear.com...
> >
> > Is there a _simple_ way to re-cast my code to become an OCX?
> 
> If your DLL is mainly a number of classes, then yes. You can make sure they 
> inherit from TCustomControl and the built-in wizard can turn them into an 
> OCX object. There are of course a few more steps to make it work, but it is 
> fairly simple (at least the second time....)
> 
> If your DLL does something completely different, well then ??

The DLL encapsulates a TCP/IP communications channel so the user does not need to know how to set up a socket and to handle the protocol.
It exposes a number of simple functions, like Connect, Login, Disconnect, RetrieveData, StartWork etc and it also has a few callback functions for events coming back from the other side.
Basically it is a kind of machine interface where the user can get the machine to do stuff and supply data and also report when certain things happen.
It has absolutely no visual component and it uses the TClientSocket internally.

PS: I am sorry for the twin posts, but I did this on the web interface (the "Forum") and it is soooo slow that I thought I had not hit the submit button so I hit it once again. :( 
I normally use a newsreader to handle this, but our IT department has in its wisdom blocked the NNTP port in the corporate firewall... DS

--
Bo B
0
Bo
11/10/2009 1:38:59 PM
<Bo Berglund> wrote in message news:181776@forums.codegear.com...
>
> The DLL encapsulates a TCP/IP communications channel so the user does not 
> need to know how to set up a socket and to handle the protocol.
> It exposes a number of simple functions, like Connect, Login, Disconnect, 
> RetrieveData, StartWork etc and it also has a few callback functions for 
> events coming back from the other side.

If all is implemented as a class with methods and events, it will work.

I do the same thing with my non-visual classes. But the inheritence is 
important (TWinControl it should be) or the wizard won't work. You can also 
turn to Eric Harmons book "Delphi COM programming", page 245. The wizard is 
explained here.
0
Uffe
11/10/2009 3:09:47 PM
Bo Berglund wrote:

> I have a DLL that I made with Delphi7 Pro 4 years ago.
> Now a client needs it but he wants to use it as an ActiveX component
> instead of a plain dll...
> 
> Is there a simple way to re-cast my code to become an OCX?

That depends on what you consider simple <G>. It is not hard, in fact.
Create a new ActiveX library project. Add an automation object to the
project using the appropriate entry in the object repository dialog.
That gets you to the type library editor. Add a new method to the
interface the type library editor has created for you for each function
the DLL exports. This method has to have the appropriate parameters and
return types to match what your exported functions now use, but since
you are restricted to automation compatible types you may have to
compromise in some cases. Let the type library editor create the
implementation for the object you designed. This gives you a COM class
with a lot of empty methods, which you now have to fill in in code.
Each of the methods you added simply calls the corresponding exported
function. That's it.

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
0
Peter
11/10/2009 6:40:36 PM
> {quote:title=Peter Below wrote:}{quote}
> Bo Berglund wrote:
> 
> > I have a DLL that I made with Delphi7 Pro 4 years ago.
> > Now a client needs it but he wants to use it as an ActiveX component
> > instead of a plain dll...
> > 
> > Is there a simple way to re-cast my code to become an OCX?
> 
> That depends on what you consider simple <G>. It is not hard, in fact.
> Create a new ActiveX library project. Add an automation object to the
> project using the appropriate entry in the object repository dialog.

Where can I find the "object repository dialog" in Delphi 7?
I created a new ActiveX library and all I got was a main file with this contents:
{code:delphi}
library Project1;
uses
  ComServ;
exports
  DllGetClassObject,
  DllCanUnloadNow,
  DllRegisterServer,
  DllUnregisterServer;
{$R *.RES}
begin
end.
{code}
I have looked in all the menus for anything talking about "Repository" but all I find is Project/AddToRepository... which brings me to a dialog where it looks like I will be adding my current project to some kind of repository...
Does not look right. :(
And on the View menu there is a TypeLibrary entry, but it is grayed out, so it is not available apparently.

> That gets you to the type library editor. Add a new method to the
> interface the type library editor has created for you for each function
> the DLL exports. This method has to have the appropriate parameters and
> return types to match what your exported functions now use, but since
> you are restricted to automation compatible types you may have to
> compromise in some cases. Let the type library editor create the
> implementation for the object you designed. This gives you a COM class
> with a lot of empty methods, which you now have to fill in in code.
> Each of the methods you added simply calls the corresponding exported
> function. That's it.
> 
When I try to use the Delphi7 help on ActiveX or OCX it looks like it is all geared towards either publishing methods of an application as COM server functions or for OCX all they talk about is Web deployment. 
I am absolutely not interested in web functions and I don't have an application which will be serving out functions.

I just want the simple DLL to become an ActiveX dll that can be registered and used as such...

Question:
Is it required that there are some visual objects/components included in an ActiveX in order for it to be possible to create?
When I read the help it seems like OCX files are always about visual components to be embedded on webpages or the like.
Is it not possible to just register the simple functions I need as a type library entry so other applications can use them?
Very confused about all this ActiveX stuff....
--
Bo B
0
Bo
11/11/2009 12:37:13 PM
<Bo Berglund> wrote in message news:182070@forums.codegear.com...
>
> Where can I find the "object repository dialog" in Delphi 7?

File > New > Other.
0
Uffe
11/11/2009 5:05:07 PM
Bo Berglund wrote:

> > {quote:title=Peter Below wrote:}{quote}
> > Bo Berglund wrote:
> > 
> > > I have a DLL that I made with Delphi7 Pro 4 years ago.
> > > Now a client needs it but he wants to use it as an ActiveX
> > > component instead of a plain dll...
> > > 
> > > Is there a simple way to re-cast my code to become an OCX?
> > 
> > That depends on what you consider simple <G>. It is not hard, in
> > fact.  Create a new ActiveX library project. Add an automation
> > object to the project using the appropriate entry in the object
> > repository dialog.
> 
> Where can I find the "object repository dialog" in Delphi 7?

As Uffe told you it is the dialog you get when you use the
File->New->Others menu. Select the ActiveX tab in this dialog and pick
the "automation object" item from that page.

> I have looked in all the menus for anything talking about
> "Repository" but all I find is Project/AddToRepository... which
> brings me to a dialog where it looks like I will be adding my current
> project to some kind of repository...  Does not look right. :( And on
> the View menu there is a TypeLibrary entry, but it is grayed out, so
> it is not available apparently.

It becomes enabled after you have added a COM object of some type to
the library project.

> When I try to use the Delphi7 help on ActiveX or OCX it looks like it
> is all geared towards either publishing methods of an application as
> COM server functions or for OCX all they talk about is Web
> deployment.  

That is only for what Delphi calls "active forms", which is a way to
wrap a Delphi form into an ActiveX control that can be used on a
browser page. Of course doing that requires the user to enable ActiveX
support in the brower settings, and nobody of a sane mind ever does
that <g>.

> Question:
> Is it required that there are some visual objects/components included
> in an ActiveX in order for it to be possible to create?  

No, not at all. OCX is the standard extension used for ActiveX
libraries that implement ActiveX custom *controls*, and those are
indeed visual controls. But the scope of ActiveX (COM, OLE, whatever
the nom de jour may be) is much broader. To create a non-visual
"component" you either use OLE automation (the interface you implement
will support IDispatch as well, although the Delphi automation object
support hides that from view), or a plain COM class. What to use
depends on the intended use of the library. Some client applications
only support automation, others can use any COM object.  ActiveX
libraries that implement non-visual components usually use the standard
DLL extension instead of OCX. The extension is totally unimportant for
making use of the library, however, it is just a convention.



-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
0
Peter
11/11/2009 7:10:24 PM
Reply: