PatrickDecottignies
asked on
set focus a component on my activeform after create
How can i set the focus to one of my components on my activeform after opening the html page and creating the activeform without user intervention ???
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I tried to duplicate your problem and my first suggestion didn't work (setting ActiveControl property at design time). However, the second suggestion did work. I published a method FormFocus similar to
procedure TActiveForm.FormFocus;
begin
SetFocus;
Edit1.SetFocus;
end;
I then called this from a javascript acting on the OnLoad event like this
<script LANGUAGE="JavaScript" FOR="window" EVENT="onLoad()">
<!--
MyActiveForm.FormFocus()
//-->
</script>
I used IE 4.01 and Delphi 3. My OLEMISC tags on TActiveFormFactory.Create were ACTIVATEWHENVISIBLE. One other thing to think about is that any activity after the call my change focus from where you set it. Hope this helps!
procedure TActiveForm.FormFocus;
begin
SetFocus;
Edit1.SetFocus;
end;
I then called this from a javascript acting on the OnLoad event like this
<script LANGUAGE="JavaScript" FOR="window" EVENT="onLoad()">
<!--
MyActiveForm.FormFocus()
//-->
</script>
I used IE 4.01 and Delphi 3. My OLEMISC tags on TActiveFormFactory.Create were ACTIVATEWHENVISIBLE. One other thing to think about is that any activity after the call my change focus from where you set it. Hope this helps!
ASKER
Can you please send me the whole description of your html page.
I'm not so familar with javascript, so i do the test but it doesn't work
I'm not so familar with javascript, so i do the test but it doesn't work
ASKER
Here it is! The important part is the object declaration for the active form object and the javascript. The object ID is the name you make up to label your active form. That way you can call to it in Javascript. I labeled mine StatWeb. "window" is the constant term for the page you are working with so that will always be the same. Hope this helps out!
<html>
<head><script LANGUAGE="JavaScript" FOR="window" EVENT="onLoad()">
<!--
StatWeb.FormFocus()
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Status</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<meta name="Microsoft Theme" content="safari 111"><meta name="Microsoft Border" content="t"></head>
<body background="_themes/safari /saftextr. jpg" bgcolor="#000000" text="#CCCC99" link="#CC9900" vlink="#996600" alink="#FF3300"><!--msnavi gation-->< table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td><!--m stheme-->< font face="trebuchet ms, arial, helvetica">
<p align="center"><br>
<img src="_derived/Status.htm_c mp_safari1 10_bnr.gif " width="600" height="60" border="0" alt="Status"></p>
<p align="center"><script language="JavaScript"><!--
MSFPhover =
(((navigator.appName == "Netscape") &&
(parseInt(navigator.appVer sion) >= 3 )) ||
((navigator.appName == "Microsoft Internet Explorer") &&
(parseInt(navigator.appVer sion) >= 4 )));
function MSFPpreload(img)
{
var a=new Image(); a.src=img; return a;
}
// --></script><script language="JavaScript"><!--
if(MSFPhover) { MSFPnav1n=MSFPpreload('_de rived/home _cmp_safar i110_hbtn. gif'); MSFPnav1h=MSFPpreload('_de rived/home _cmp_safar i110_hbtn_ a.gif'); }
// --></script><a href="./" onmouseover="if(MSFPhover) document['MSFPnav1'].src=M SFPnav1h.s rc" onmouseout="if(MSFPhover) document['MSFPnav1'].src=M SFPnav1n.s rc"><img src="_derived/home_cmp_saf ari110_hbt n.gif" width="140" height="60" border="0" alt="Home" align="middle" name="MSFPnav1"></a></p>
<p align="center"> </p>
<!--mstheme--></font></td> </tr><!--m snavigatio n--></tabl e><!--msna vigation-- ><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><!--msnav igation--> <td valign="top"><!--mstheme-- ><font face="trebuchet ms, arial, helvetica">
<p align="center"><script LANGUAGE="JavaScript">
</script>
<object ID="StatWeb" WIDTH="464" HEIGHT="712" align="center" hspace="0" vspace="0" CLASSID="CLSID:30831D6F-C9 85-11D1-9C 9C-0060B0A 11A32" CODEBASE="http://mtdmalan/newhire/XStatus.ocx#version=1,0,0,0">
</object>
<!--mstheme--></font><!--m snavigatio n--></td>< /tr><!--ms navigation --></table ></body>
</html>
<html>
<head><script LANGUAGE="JavaScript" FOR="window" EVENT="onLoad()">
<!--
StatWeb.FormFocus()
//-->
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Status</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<meta name="Microsoft Theme" content="safari 111"><meta name="Microsoft Border" content="t"></head>
<body background="_themes/safari
<p align="center"><br>
<img src="_derived/Status.htm_c
<p align="center"><script language="JavaScript"><!--
MSFPhover =
(((navigator.appName == "Netscape") &&
(parseInt(navigator.appVer
((navigator.appName == "Microsoft Internet Explorer") &&
(parseInt(navigator.appVer
function MSFPpreload(img)
{
var a=new Image(); a.src=img; return a;
}
// --></script><script language="JavaScript"><!--
if(MSFPhover) { MSFPnav1n=MSFPpreload('_de
// --></script><a href="./" onmouseover="if(MSFPhover)
<p align="center"> </p>
<!--mstheme--></font></td>
<p align="center"><script LANGUAGE="JavaScript">
</script>
<object ID="StatWeb" WIDTH="464" HEIGHT="712" align="center" hspace="0" vspace="0" CLASSID="CLSID:30831D6F-C9
</object>
<!--mstheme--></font><!--m
</html>
ASKER