通过JavaScript向ActiveX控件传递数据的问题?(300分)

C

ccw128

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟正在学ActiveX编程,现在有一个问题:
我开发了一个ActiveX,现在想通过网页向这个ActiveX传递一个字符串列表(包含一
系列字符串)和一个布尔变量,我问了一个专家,他建议我在ActiveX中写两个函数
AddString和SetBool,并在网页中JavaScript反复调用AddString,把字符串列表中的所有
字符串逐一传递给控件,以及用SetBool把布尔变量传递给控件。请问这种方法好不好?还
有我不知道如何按照他的思路写程序(包括ActiveX和JavaScript的部分),各位能否给一
个例子,让我参考一下?
 
传递用特别字符分隔的一个字符串比较好。。
一个布尔变量么,可以是跟在字符串最后的一个字符标记,
比仿:f/F是False,t/T是True,o/O是未知。
取得字符串时先取出布尔变量,然后分析字符串由哪些子字符串组成。
 
那ActiveX中的函数应该怎么定义? 是这样吗?
function MyFunction(const AString: PChar);

还有JavaScript应该怎么写,我不会Js的。
 
这个我实现过,如果需要请将你的EMail传给我。
leezhenghui@163.com
 
可以在制作ACTIVEXFORM 时,向ACTIVEXFORM添加属性或过程,然后,你自己在相应的位置填写代码就好。
 
在制作ActiveForm时加入(只写)属性,控件程序自动加入一个Function,在这个Function中传递一个参数给ActiveForm的一个全局变量,以备它用。
在JS脚本中可给这个(只写)属性赋值,最后来个初始化Init()(这个函数在控件中也要加入),告诉控件已经传入参数。

//HTML文件
<HTML>
<head>
<script>
function load()
{
play.comAddress="172.16.47.138"

play.comPort=1000;
play.RoadNameList="山东路,1,6;福州路,2,2;香港路,3,8";
play.CurrentRoadID=2;
play.UserName="guest"

play.UserAuth =3

play.Init()

}
</script>
</head>

<body onload="load()">

<OBJECT id="play"
classid="clsid:2C756F25-49A6-4A5C-A6FD-BAA6286506F9"
codebase="http://proboy/New/test/video/PlayVideo.inf"
width=750
height=450
align=center
hspace=0
vspace=0
>
</OBJECT>

</body>
</HTML>

//ActiveForm程序

.........
{参数传入}
procedure TActiveMovie.Set_CurrentRoadID(Value: Integer);
begin
FCurrentRoadID:=value;
end;

procedure TActiveMovie.Set_RoadNameList(const Value: WideString);
begin
FRoadNameList:=value;
end;

procedure TActiveMovie.Set_UserAuth(Value: Integer);
begin
FUserAuth:=Value;
end;

procedure TActiveMovie.Set_UserName(const Value: WideString);
begin
FUserName:=Value;
end;

procedure TActiveMovie.Set_comAddress(const Value: WideString);
begin
FAddress:=value;
end;

procedure TActiveMovie.Set_comPort(Value: Integer);
begin
FPort:=Value;
end;

procedure TActiveMovie.Init;
begin
InitRoad();
SendCommand('LOGIN');
end;
.........
procedure TActiveMovie.SubmitCommand(v:integer;c:string)
//命令发送
var
str:String;
Begin
if(FCurrentCamID>0) then
Begin
str:=IntToStr(FCurrentCamID)+'#a';
if ( v=0 ) then v:=1
if ( v>0 ) then str:=str+IntToStr(V);
if (c<>'') then
Begin
str:=str+c;
SendCommand(str);
End;
End
Else
DisplayInfo('没有选择路口!');

End;
procedure TActiveMovie.InitRoad();//初始化路口数组
var
ch1,ch2:char;
str,tmp:string;
loc:integer;
Begin
ch1:=';';
ch2:=',';
cbxRoadName.Items.Clear;
if (Length(FRoadNameList)>0) then
Begin
tmp:=FRoadNameList;
While (tmp<>'') do
Begin
loc:=Pos(ch1,tmp);
if (loc>0) then
Begin
str:=Copy(tmp,1,loc-1);
tmp:=Copy(tmp,loc+1,Length(tmp)-loc);
End
Else
Begin
str:=tmp;
tmp:='';
End;
SetLength(Roads,Length(Roads)+1);

loc:=Pos(ch2,str);
Roads[Length(Roads)-1].RoadName:=Copy(str,1,loc-1);
cbxRoadName.Items.Add(Copy(str,1,loc-1));

str:=Copy(str,loc+1,Length(str)-loc);
loc:=Pos(ch2,str);
Roads[Length(Roads)-1].RoadID :=StrToInt(Copy(str,1,loc-1));

str:=Copy(str,loc+1,Length(str)-loc);
Roads[Length(Roads)-1].CamID:=StrToInt(str);

if (Roads[Length(Roads)-1].RoadID=FCurrentRoadID) then
Begin
cbxRoadName.Text:= Roads[Length(Roads)-1].RoadName;
FCurrentCamID:=Roads[Length(Roads)-1].CamID;
End

End;
End;
End;
.........



 

Similar threads

回复
0
查看
864
不得闲
S
回复
0
查看
956
SUNSTONE的Delphi笔记
S
顶部