egono
asked on
ActiveX form input for html page
I'm new to ActiveX.
I want to create a ActiveX form which will be embedded in a html page. The ActiveX form should be a TDateTimePicker to select a date. I want to send the selected date and some other html input fields back to the server.
Sample:
<html>
<body>
<form method="post" action="http://myserver/mycgi">
my statement: <input size=12 name="statement">
my birthday: <my ActiveX select date form>
</form>
</body>
</html>
How do I create such a ActiveX in delphi 5? Is it possible to send binary data (a image) from a ActiveX via a html form post to the server? Any help is appreciated.
I don't care about security issues and I can't use java or javascript.
thanks ...
I want to create a ActiveX form which will be embedded in a html page. The ActiveX form should be a TDateTimePicker to select a date. I want to send the selected date and some other html input fields back to the server.
Sample:
<html>
<body>
<form method="post" action="http://myserver/mycgi">
my statement: <input size=12 name="statement">
my birthday: <my ActiveX select date form>
</form>
</body>
</html>
How do I create such a ActiveX in delphi 5? Is it possible to send binary data (a image) from a ActiveX via a html form post to the server? Any help is appreciated.
I don't care about security issues and I can't use java or javascript.
thanks ...
ASKER
mike:
1. I don't know - it's just a fact.
2. I have to do this in delphi.
1. I don't know - it's just a fact.
2. I have to do this in delphi.
There are many better solutions than ActiveX but this is how to create an ActiveX control:
File|New. go to the ActiveX tab and select ActiveForm.
In fact, read this article from Delphi Informant magazine, it is how I did my first one:
http://www.delphiinformant.com/features/1999/06/di199906tt_f/di199906tt_f.asp
J.
File|New. go to the ActiveX tab and select ActiveForm.
In fact, read this article from Delphi Informant magazine, it is how I did my first one:
http://www.delphiinformant.com/features/1999/06/di199906tt_f/di199906tt_f.asp
J.
As jsweby noted it's easy (in professional or better versions) to create activeX wrappers around a vcl. The tricky part is posting the data to the cgi service. If you don't have scripting support I would think you'd have to implement that functionality in the activex control - meaning your form wouldn't submit the data your activex control would. Then that control would need to know how to access it's parent's DOM. Hmmm, have to think about that one.
GL
Mike
GL
Mike
ASKER
Ok - I created a ActiveX, but I still don't know how to transfer the data to the html form.
Any suggestions are welcome!
Any suggestions are welcome!
That's what I'm wondering - I almost think it would be easier to create the entire form as an activeX control the can send the data itself. As far as I know there is no way to dynamically set the values of the html form without some sort of scripting. OTOH if you created the instance of IE in some way that left you with a ref to it's document object (ie:
var
doc : variant;
begin
doc := createOLEObject('InternetE xplorer.Ap lication') ;
doc.navigate('about:blank' );
doc := doc.document;//doc now points to the html document
then you can manipulate it howver you wish. Now there might be someway to get the document refrence if you've got the window handle (as I would think plugin's would have to) but I really don't know how. In light of this I would prob.:
1) alter your control to descned from TPanel instead
2) add an HTTP control, I like the indy components: http://www.nevrona.com/indy
3) add edits & buttons & such as to recreate the html form
4) let the control send all the info to the cgi.
GL
Mike
var
doc : variant;
begin
doc := createOLEObject('InternetE
doc.navigate('about:blank'
doc := doc.document;//doc now points to the html document
then you can manipulate it howver you wish. Now there might be someway to get the document refrence if you've got the window handle (as I would think plugin's would have to) but I really don't know how. In light of this I would prob.:
1) alter your control to descned from TPanel instead
2) add an HTTP control, I like the indy components: http://www.nevrona.com/indy
3) add edits & buttons & such as to recreate the html form
4) let the control send all the info to the cgi.
GL
Mike
ASKER
the datetimepicker is a very small part of the form and I don't want to create such a huge ActiveX with all input fields.
do you have a solution with JavaScript enabled?
do you have a solution with JavaScript enabled?
Sure, MS has in their msdn library a dhtml behavior of very similar functionality. You can get it here: http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/behaviors/library/calendar/default.asp. here's an example:
<html>
<head>
<script>
var months = ['Jan','Feb','Mar','Apr',' May','Jun' ,'Jul','Au g','Sept', 'Oct','Nov ','Dec'];
function addDate()
{
with (document.all.calendar)
{
document.all.dates.value += months[month-1]+' '+day+', '+year+'\n';
};
};
</script>
</head>
<body>
<div style="behavior: url(c:\windows\calendar.ht c);width: 100px;height: 100px;)" id="calendar"></div>
<form><input type="button" onclick="addDate();"></for m>
<textArea readOnly=true id="dates"></textArea>
</body>
</html>
GL
Mike
<html>
<head>
<script>
var months = ['Jan','Feb','Mar','Apr','
function addDate()
{
with (document.all.calendar)
{
document.all.dates.value += months[month-1]+' '+day+', '+year+'\n';
};
};
</script>
</head>
<body>
<div style="behavior: url(c:\windows\calendar.ht
<form><input type="button" onclick="addDate();"></for
<textArea readOnly=true id="dates"></textArea>
</body>
</html>
GL
Mike
ASKER
that's not what I'm looking for
I meant do you have a solution to exchange data between the ActiveX and the html form with JavaScript enabled?
I meant do you have a solution to exchange data between the ActiveX and the html form with JavaScript enabled?
ASKER
I found this article, but I don't understand it.
Accessing the Object Model from Within an ActiveX Control
http://support.microsoft.com/support/kb/articles/Q172/7/63.ASP
Accessing the Object Model from Within an ActiveX Control
http://support.microsoft.com/support/kb/articles/Q172/7/63.ASP
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks - i will try that tomorrow
ASKER
I had no time to test it so far
where did you find these articles?
where did you find these articles?
The first example was largely based on the article you prived - the second came from a usenet article. Usenet is a _great_ place to look for such things, I recomend deja, or rather (now) googles search engine (www.deja.com)
GL
Mike
GL
Mike
ASKER
i've got some things working - some don't ...
i'm using this procedure to get some infos
var myWebDocument:HTMLDocument ;
myWebApp:IWebBrowserApp;
[...]
procedure GetBrowserInfos;
var
myIOleClientSite : IOleClientSite;
myISP : IServiceProvider;
myIVCLComObject : IVCLComObject;
myOleObject : IOleObject;
begin
try
myIVCLComObject:=IVCLComOb ject(VCLCo mObject);
myOleObject:=myIVCLComObje ct as IOleObject;
myOleObject.GetClientSite( myIOleClie ntSite);
myISP:=myIOleClientSite as IServiceProvider;
myISP.QueryService(IWebBro wserApp, IWebBrowserApp, myWebApp);
myWebDocument:=myWebApp.Do cument as HTMLDocument;
except end;
end;
Now it's seems possible to access the form elements via myWebDocument.forms.item, but I have no clue how to do this. Let's say I want to access the form element named "InputField1" - myWebDocument.forms.item[' InputField 1'] won't work
do you have any ideas?
btw - I will increase the points if you want or I create a new question if you want your points now - just tell me
i'm using this procedure to get some infos
var myWebDocument:HTMLDocument
myWebApp:IWebBrowserApp;
[...]
procedure GetBrowserInfos;
var
myIOleClientSite : IOleClientSite;
myISP : IServiceProvider;
myIVCLComObject : IVCLComObject;
myOleObject : IOleObject;
begin
try
myIVCLComObject:=IVCLComOb
myOleObject:=myIVCLComObje
myOleObject.GetClientSite(
myISP:=myIOleClientSite as IServiceProvider;
myISP.QueryService(IWebBro
myWebDocument:=myWebApp.Do
except end;
end;
Now it's seems possible to access the form elements via myWebDocument.forms.item, but I have no clue how to do this. Let's say I want to access the form element named "InputField1" - myWebDocument.forms.item['
do you have any ideas?
btw - I will increase the points if you want or I create a new question if you want your points now - just tell me
Just a comment to receive notifications...
I figured it out using edey's SetIeWebBrowser method to find the HTMLDocument. The html code below has a form named 'form1' with a text field named 'datetime'.
<html>
<head>
<title>ActiveX Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<object width="219" height="156" classid="clsid:B86D459F-E4 A7-4D24-97 D0-95409C2 C140B" name="aform">
</object>
<form name="form1" method="post" action="">
<input type="text" name="datetime">
</form>
</body>
</html>
Here are the code snippets:
TMyActiveForm = class(TActiveForm, IMyActiveForm)
...
private
IeWebAppFound: Boolean;
IeServiceProvider: IServiceProvider;
IeWebBrowser: IWebBrowserApp;
IeContainer: IOleContainer;
IeDocument: HTMLDocument;
...
procedure TMyActiveForm.SetIeWebBrow ser;
begin
IeWebAppFound := False;
IeContainer := nil;
while not IeWebAppFound do
begin
if IeContainer = nil then
ActiveFormControl.ClientSi te.QueryIn terface(II D_IService Provider, IeServiceProvider)
else
IeContainer.QueryInterface (IID_IServ iceProvide r, IeServiceProvider);
IeServiceProvider.QuerySer vice(IID_I WebBrowser App, IID_IWebBrowserApp, IeWebBrowser);
if IeWebBrowser = nil then
Break;
if IeWebBrowser.TopLevelConta iner then
begin
IeWebAppFound := True;
end
else begin
if IeWebBrowser.Container = nil then
Break;
IeContainer := IeWebBrowser.Container as IOleContainer;
end;
end;
end;
procedure TMyActiveForm.DateTimePick er1Change( Sender: TObject);
var frm: HTMLFormElement;
txt: HTMLTextAreaElement;
begin
if not IeWebAppFound then
SetIeWebBrowser;
if not IeWebAppFound then
Exit;
IeDocument := IeWebBrowser.Document as HTMLDocument;
if IeDocument = nil then
ShowMessage('Document = nil')
else begin
frm := (IeDocument.forms.item('fo rm1', 0) as HTMLFormElement);
txt := (frm.item('datetime', 0) as HTMLTextAreaElement);
txt.value := DateTimeToStr(DateTimePick er1.DateTi me);
end;
end;
<html>
<head>
<title>ActiveX Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<object width="219" height="156" classid="clsid:B86D459F-E4
</object>
<form name="form1" method="post" action="">
<input type="text" name="datetime">
</form>
</body>
</html>
Here are the code snippets:
TMyActiveForm = class(TActiveForm, IMyActiveForm)
...
private
IeWebAppFound: Boolean;
IeServiceProvider: IServiceProvider;
IeWebBrowser: IWebBrowserApp;
IeContainer: IOleContainer;
IeDocument: HTMLDocument;
...
procedure TMyActiveForm.SetIeWebBrow
begin
IeWebAppFound := False;
IeContainer := nil;
while not IeWebAppFound do
begin
if IeContainer = nil then
ActiveFormControl.ClientSi
else
IeContainer.QueryInterface
IeServiceProvider.QuerySer
if IeWebBrowser = nil then
Break;
if IeWebBrowser.TopLevelConta
begin
IeWebAppFound := True;
end
else begin
if IeWebBrowser.Container = nil then
Break;
IeContainer := IeWebBrowser.Container as IOleContainer;
end;
end;
end;
procedure TMyActiveForm.DateTimePick
var frm: HTMLFormElement;
txt: HTMLTextAreaElement;
begin
if not IeWebAppFound then
SetIeWebBrowser;
if not IeWebAppFound then
Exit;
IeDocument := IeWebBrowser.Document as HTMLDocument;
if IeDocument = nil then
ShowMessage('Document = nil')
else begin
frm := (IeDocument.forms.item('fo
txt := (frm.item('datetime', 0) as HTMLTextAreaElement);
txt.value := DateTimeToStr(DateTimePick
end;
end;
You can also post data inside the ActiveForm directly using the WebBrowser.Navigate method.
Hi, can you get it to work?
ASKER
I'm busy at customers - hopefully next week I'm back at work, then I will try it - thanks so far ...
ASKER
Epsylon - it seems to work, thanks! is it ok for you if give the points to edey anyway? he did the first important step
ASKER
Epsylon, edey - are you still listening?
any suggestions how to give the points?
any suggestions how to give the points?
Hmm, I think that's something you'd have to talk to C/S about.
GL
Mike
GL
Mike
ASKER
Mike - are 50 points ok for you?
Give the points to edey...
ASKER
ok - Epsylon next time you will get some more :-)
thanks again to both of you!
thanks again to both of you!
Thanks, Glad to be of service.
GL
Mike
GL
Mike
GL
Mike