Difference between revisions of "CAEngine::SetCallbackObject/zh"
(Created page with "在ADE计算一个模型或者typescript时,当模型在计算机Analytica中被计算时,将遇到各种要求用户交互的函数。例如,如果一个表达式包含...") |
(Created page with "ADE给各种事件(函数或指令)定义各种回调接口,可能触发用户接口交互。目前,存在下面的接口: * IAMsgBoxCallback") |
||
Line 13: | Line 13: | ||
[[CAEngine::SetCallbackObject/zh|CAEngine::SetCallbackObject]]给用户提供了一种方法在遇到这种事件发生时接收回调,这样你的程序可以采取预期的动作,例如给用户显示一个信息框。 | [[CAEngine::SetCallbackObject/zh|CAEngine::SetCallbackObject]]给用户提供了一种方法在遇到这种事件发生时接收回调,这样你的程序可以采取预期的动作,例如给用户显示一个信息框。 | ||
− | + | ADE给各种事件(函数或指令)定义各种回调接口,可能触发用户接口交互。目前,存在下面的接口: | |
− | * [[IAMsgBoxCallback]] | + | * [[IAMsgBoxCallback/zh|IAMsgBoxCallback]] |
:''Note: the plan is that once this is moved past the experimental stage, other callback interfaces will be added, for things such as [[ShowProgressBar]], [[AskMsgNumber]], [[AskMsgText]], display warning, [[Show|Show command]] (show result, show definition, show graph), etc.'' | :''Note: the plan is that once this is moved past the experimental stage, other callback interfaces will be added, for things such as [[ShowProgressBar]], [[AskMsgNumber]], [[AskMsgText]], display warning, [[Show|Show command]] (show result, show definition, show graph), etc.'' |
Revision as of 02:17, 23 October 2015
ADE User Guide > ADE Server Class Reference > CAEngine
该特征目前正处于试验阶段。
CAEngine::SetCallbackObject(IUnknown* pCallbackObj)
在ADE计算一个模型或者typescript时,当模型在计算机Analytica中被计算时,将遇到各种要求用户交互的函数。例如,如果一个表达式包含一个MsgBox函数,Analytica将在一个信息框内显示一个问题,要求获取用户的回答。因为ADE不包含用户接口,将不会直接处理这些用户交互。 CAEngine::SetCallbackObject给用户提供了一种方法在遇到这种事件发生时接收回调,这样你的程序可以采取预期的动作,例如给用户显示一个信息框。
ADE给各种事件(函数或指令)定义各种回调接口,可能触发用户接口交互。目前,存在下面的接口:
- Note: the plan is that once this is moved past the experimental stage, other callback interfaces will be added, for things such as ShowProgressBar, AskMsgNumber, AskMsgText, display warning, Show command (show result, show definition, show graph), etc.
用法
To use a callback, you must implement a COM class that derives from the interfaces you want to handle and implements their methods. As a COM class, it must implement the standard IUnknown::QueryInterface COM method, which must report that it supports each of these interfaces. You then instantiate an instance of that class and pass it to this method.
在C++ 中
#使用ADE和 (不间断空格)输入"ADE.exe"; class MyCallback : public IAMsgBoxCallback { public: STDMETHODIMP QueryInterface(REFIID riid, LPVOID* ppv) { if (riid==IID_IUnknown) { *ppv = (LPVOID)dynamic_cast<IUnknown*>(this); } else if (riid == __uuidof(IAMsgBoxCallback)) { *ppv = (LPVOID)dynamic_cast<IAMsgBoxCallback*>(this); } else { *ppv = NULL; return E_NOINTERFACE; } AddRef(); return S_OK; } STDMETHOD(ShowMsgBox)(BSTR title, BSTR text, LONG buttons, LONG* /*out*/ whatPressed) { *whatPressed = MessageBox(NULL,text,title,buttons); return S_OK; } }; void main() { CoInitialize(NULL); CAEnginePtr pAde(__uuidof(_CAEngine)); pAde->SetCallbackObject(new MyCallback); ... CoUninitilize(); }
在C#中
We have not yet been able to get this to work from .NET -- which is why this is still considered an experimental feature. We believe the C# implementation should look something like what we show here. Since we haven't gotten it to successfully work yet, we're obviously not quite there. Our two theories are that some additional .NET attribute decoration on the class is still required, or that some additional registry settings need to be configured. We provide this here to aid with experimentation.
using ADE; namespace MyApp { [Guid("2576608A-833D-4742-BF63-794869E642C3")] // use the Create GUID tool in DevStudio to create your own unique GUID [ClassInterface(ClassInterfaceType.None)] public class MyCallback : IAdeMsgBoxCallback { public int ShowMsgBox(string title, string text, int buttons) { MessageBoxButtons btns = (MessageBoxButtons)buttons; DialogResult res = MessageBox.Show(text, title, btns); return (int)res; } } class Program { static void Main(string[] args) { CAEngine ade = new CAEngine(); ade.SetCallbackObject(new MyCallback()); ... } } }
Enable comment auto-refresher