CAEngine::SetCallbackObject

Revision as of 02:29, 23 October 2015 by Jhuawen (talk | contribs) (Created page with "要使用回调,你必须执行一个由你想处理和执行其方法的接口所驱动的COM类型。作为一个COM类型,你必须执行标准的''IUnknown::QueryInter...")

ADE User Guide > ADE Server Class Reference > CAEngine

Other languages:
English • ‎中文

ADE 4.3新特征

该特征目前正处于试验阶段。

CAEngine::SetCallbackObject(IUnknown* pCallbackObj)

在ADE计算一个模型或者typescript时,当模型在计算机Analytica中被计算时,将遇到各种要求用户交互的函数。例如,如果一个表达式包含一个MsgBox函数,Analytica将在一个信息框内显示一个问题,要求获取用户的回答。因为ADE不包含用户接口,将不会直接处理这些用户交互。 CAEngine::SetCallbackObject给用户提供了一种方法在遇到这种事件发生时接收回调,这样你的程序可以采取预期的动作,例如给用户显示一个信息框。

ADE给各种事件(函数或指令)定义各种回调接口,可能触发用户接口交互。目前,存在下面的接口:

注意:此计划是:一旦这通过实验阶段,将添加其它回调接口,对于一些事件,例如ShowProgressBarAskMsgNumberAskMsgText、显示警告、Show command(显示结果、显示定义、显示图形)等等。。

用法

要使用回调,你必须执行一个由你想处理和执行其方法的接口所驱动的COM类型。作为一个COM类型,你必须执行标准的IUnknown::QueryInterface COM 方法,这必须报告它支持所有这些接口。然后你再实例化那个类型的例子并将它传给此方法。

在C++ 中

#使用ADE和&nbsp(不间断空格)输入"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")]    // 使用DevStudio中的Create 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());
           ...
       }
    }
}
Comments


You are not allowed to post comments.