Entry
Delphi: ActiveX Control: Create: Simple: How to create a Delphi executable and run it in IE browser?
Sep 4th, 2004 17:14
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 08 October 2003 - 10:15 pm --------------------
Delphi: ActiveX Control: Create: Simple: How to create a Delphi
executable and run it in IE browser?
---
The idea of an ActiveX control is that it allows your Delphi program
(thus some binary executable, and Delphi you can program to do
almost whatever action, like loading or saving files on the client
computer) to run inside a browser running on your computer (it is just
a special case of OLE, in which an application runs in another
application).
---
So if you insist or it is insisted that most actions should be done on
the client side in a browser you could use an ActiveX control.
---
Running any binary application in your browser will or might involve
security.
So running it usually will be restricted by design, except when you
grant yourself explicitely permission for this.
Optionally you can further digitally sign as being secure the ActiveX
controls that you create (e.g. locally as described below, or via
VeriSign (this is paid), so they can run on other computers also).
---
Note:
By design an ActiveX control will (currently as far as I know) only run
in a Microsoft Internet Explorer browser.
---
---
Steps: Overview:
1. -Create your ActiveX control
2. -Deploy it for the Web
3. -Register your ActiveX control using
the executable 'regsvr32.exe'
4. -Run the created HTML file in your browser
---
---
Steps: Worked out:
1. -Create your ActiveX control
1. Start Delphi
2. Create an 'Active Form'
1. -Select from menu option 'File'
2. -Select from list 'New'
3. -Select from list 'Other...'
4. -Select tab 'ActiveX'
5. -Click on icon 'Active Form'
3. Put something on this form (optional)
e.g.
1. Put a button on the form
(put it in the left upper corner or else it might not be
visible in your Internet page later. The size of the window
shown in your Internet page you can set with the <OBJECT>
parameters 'width' and 'height' in the .htm page which
Delphi will generate for you, similar to an applet)
2. Put a 'file open dialog' box on the form
(palette 'Dialogs', choose 'OpenDialog')
3. Put a 'file save dialog' box on the form
(palette 'Dialogs', choose 'SaveDialog')
4. Double click on this button
5. Write the text
ShowMessage( 'Do something' );
OpenDialog1.Execute;
ShowMessage( 'You chose to load the file' +
OpenDialog1.Filename );
SaveDialog1.Execute;
ShowMessage( 'You chose to save the file' + ' ' +
SaveDialog1.Filename );
4. Possibly save your project in
a directory of your liking
(menu 'File'->'Save all',
browse to your directory
e.g.
c:\temp
and press the 'Save' button twice)
1. This will create a couple
of files in that directory,
the most important is the
file with the extension .ocx
which contains your just created
ActiveX control
e.g.
ActiveFormProj1.ocx
2. -Deploy it for the Web
1. -Select from menu option 'Project'
2. -Select from list 'Web Deploy'
1. -In the text box 'Target dir'
type or browse to the directory where your .ocx file
is located
e.g.
c:\temp
2. -In the text box 'Target URL'
type or browse to the directory where your .ocx file
will be deployed
(do not choose this to be the same as your
current .ocx directory, or you will get the
error '.ocx in use by another process', when
you try to save your result)
e.g.
c:\anotherdirectory
3. -In the text box 'HTML Dir'
type or browse to the directory where your .htm file
(which will automatically be generated by Delphi)
should be located
e.g.
c:\anotherdirectory
3. -Click button 'OK'
3. If you want to run it from Delphi, you could
1. -Select from menu option 'Run'
2. -Select from list 'Parameters'
3. -Select as 'Host application'
your Microsoft Internet Explorer
browser
e.g.
C:\Program Files\Internet Explorer\iexplore.exe
4. -Select as 'Parameter' the name of the
generated .htm file directory
e.g.
c:\anotherdirectory\ActiveFormProj1.htm
5. -Click button 'OK'
6. -Register your ActiveX control using
the executable 'regsvr32.exe'
on the MSDOS command line type the command
regsvr32.exe <your .ocx filename>
e.g.
regsvr32.exe c:\temp\ActiveFormProj1.ocx
That should show 'DllRegisterServer in <your .ocx filename>
succeeded.
e.g.
'DllRegisterServer in ActiveFormProj1.ocx succeeded'
---
Note:
This will have created some entries in the Windows registry,
so that your .ocx ActiveX can be trusted on this computer.
---
Note:
If you do not register your .ocx file, you will get a message
that the ActiveX can not be safely run in your browser (Your
current security settings prohibit running ActiveX controls on
this page. As a result, the page may not display correctly),
and you will not see the form shown (or just as an image with
a 'x' in it) in your browser.
---
Note:
For testing purposes of your own Delphi ActiveX programs, you
might have to set security settings in your Microsoft Internet
Explorer browser (menu 'Tools'->'Internet Options...'->tab
'Security'->button 'Custom level'->select radiobutton 'Prompt'
in 'Initialize and Script ActiveX controls not marked as
safe').
7. -Run your application (e.g. click on the green '>'
or press the <F9> key).
8. -That will start your browser with that form
in it
9. -Repeat the above steps until your are satisfied with
the result
4. -Run the created HTML file in your browser
1. In the directory where you during the 'Web deploy'
chose to store your .htm file
(e.g. in c:\anotherdirectory) there was also created a
.htm file, similar to the following:
--- cut here: begin --------------------------------------------------
<HTML>
<TITLE> Delphi ActiveX Test Page </TITLE>
<H1> Delphi ActiveX Test Page </H1>
<P/>
You should see your Delphi forms or controls embedded in the form
below.
<HR/>
<CENTER/>
<P/>
<OBJECT
classid="clsid:5DEE205E-9C70-42F7-B0B5-A4CF8C711D30"
codebase="c:/temp/ActiveFormProj1.ocx#version=1,0,0,0"
width=350
height=250
align=center
hspace=0
vspace=0
>
</OBJECT>
</HTML>
--- cut here: end ----------------------------------------------------
1. Load this .htm file in your browser
1. Start your Microsoft Internet Explorer browser
2. Type the full path of your .htm file in that .ocx
directory as the URL
e.g. type
c:\temp\ActiveFormProj1.htm
3. You should now see a page in your browser showing
the form you just created in Delphi
figure: Your Microsoft Internet Explorer browser
showing your .htm page:
+---------------------------------------------------------+
|+-------------------------------------------------------+|
||c:\another directory\ActiveFormProj1.htm ||
|+-------------------------------------------------------+|
| |
| Delphi ActiveX Test Page |
| |
| You should see your Delphi forms or controls embedded |
| in the form below. |
| |
| +----------------------------------+ |
| | | |
| | | |
| | +----------------------+ | |
| | | Button1 | | |
| | +----------------------+ | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| +----------------------------------+ |
+---------------------------------------------------------+
4. If you click on the button, it should show
'Do something' in a message box, and you can
(by simulation) choose and save a file.
---
---
Tested successfully on Microsoft Windows XP Professional running Delphi
7.
---
---
Internet: see also:
---
[Internet: see also: http://www.google.com search for 'ActiveX
JavaScript Delphi':
http://delphi.about.com/library/weekly/aa042099.htm]
http://delphi.about.com/gi/dynamic/offsite.htm?site=http%3A%2F%
2Fpweb.netcom.com%2F%7Echerrman%2Fdl030.htm
---
Delphi: Internet: Browser: How make Delphi .exe accessible from
Microsoft Internet Explorer browser?
http://www.faqts.com/knowledge_base/view.phtml/aid/25246/fid/175
---
---
Book: see also:
---
[book: Lalani, Suleiman / Chandak, Ramesh - ActiveX programmer's
library - Jamsa Press - ISBN 1-884133-52-5]
----------------------------------------------------------------------