Board index » cppbuilder » MS ScripControl - AddObject() problem

MS ScripControl - AddObject() problem

2007-05-30 03:22:25 PM
Hello all,
I have problems using the MS-ScripControl regarding the AddObject() method.
This means I can't refer to an internal function (of my application) which I
supposed to offer to the script component via AddObject(). (Let me say that
the scripting functionality itself works properly - I can use AddCode() /
Eval() ... so that I'm basically able to run simple scripts.)
For testing purposes I created a COM-automation object "ScriptControlTest"
which has the interface "ITest" with the method MyMessage(BSTR szMsg) which
only shows a message box.
Here's a code snippet in which I tried out several alternatives:
typedef Scriptcontroltest_tlb::ITestPtr IScriptTestPtr;
IScriptTestPtr pIScriptTest;
hr = pIScriptTest.CreateInstance(L"ScriptControlTest.Test", NULL,
ScriptControl1->AddObject(L"Test", pIScriptTest, false);
Variant vAutoObj.CreateObject(L"ScriptControlTest.Test");
ScriptControl1->AddObject(L"Test", vAutoObj, false);
Variant vAutoObj = CreateOleObject("ScriptControlTest.Test");
ScriptControl1->AddObject(L"Test", vAutoObj, false);
But all my efforts only lead to the effect that I received the message
"'Test' is undefined" when I tried to run the following script code for
example (JScrip syntax):
Has anyone experience with that and can give me a hint or is there a BCB
(NOT Delphi!!!) sample project/tutorial anywhere?

Re:MS ScripControl - AddObject() problem

"Uli" < XXXX@XXXXX.COM >wrote in message
I have problems using the MS-ScripControl regarding the AddObject()
Rather than using the ScriptControl, I would suggest using the
IActiveScript interface directly instead, in particular the
IActiveScript::AddNamedItem() method and the
IActiveScriptSite::GetItemInfo() event.
In short, you implement an object in our own code that derives from
the IActiveScriptSite interface, then use CoCreateInstance() to
instantiate the desired scripting engine (VBScript, JScript, etc),
query it for the IActiveScript interface, and call its SetScriptSite()
method, passing it a pointer to an instance of your IActiveScriptSite
object. You then use IActiveScript::AddNamedItem() to add the desired
named object to the scripting environment. The scripting engine will
call your code's implementation of the
IActiveScriptSite::GetItemInfo() event whenever the script needs
access to the IUnknown and/or ITypeInfo interface for that named
object. It is really not very difficult to set up at all. I once
wrote a wrapper class around IActiveScript and related interfaces, and
it works quite well in my company's production products.