SAP:タイプ 'System .__ ComObject'のCOMオブジェクトをインターフェイスタイプ 'sapfewse.GuiTextField'にキャストできません

Phil_BHN

c#を使用してSAPGUIウィンドウとインターフェイスしようとしています。ここでこのソリューションを使用します:ソリューション、開いているGUIウィンドウに正常に接続しました。コマンドを送信できます

frame.Maximize();

予想どおり、ウィンドウが最大化されます。

テキストボックスにテキストを入力しようとすると、問題が発生します。

((GuiTextField)session.FindById("wnd[0]/tbar[0]/okcd")).Text = "InputText";
    //or
    GuiTextField targetField =
    (GuiTextField)session.FindById("wnd[0]/tbar[0]/okcd");
    //or
    GuiTextField targetField =
    (GuiTextField)session.FindById("wnd[0]/tbar[0]/okcd", "GuiTextField");
    targetField.Text = "InputText";

私が得るエラーは次のとおりです。

System.InvalidCastException
  HResult=0x80004002
  Message=Unable to cast COM object of type 'System.__ComObject' to interface type 'sapfewse.GuiTextField'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B4D89EE3-6EFD-4F4C-9F42-AD42B71C8EB7}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

代わりにこれを試してみると:

var x = session.FindById("wnd[0]/tbar[0]/okcd");

次に、ウォッチウィンドウに、xはGuiTextFieldではなく、GuiComponent型であることが示されます。

これは実行されます:

GuiComponent targetField = (GuiComponent)session.FindById("wnd[0]/tbar[0]/okcd");

ただし、targetFieldにはtextプロパティがありません。

これを修正するには何をする必要がありますか?ありがとう!

Phil_BHN

答えを見つけました。他の誰かを助けることができる場合に備えて、ここに残しておきます。

見つめている

GuiComponent targetField = (GuiComponent)session.FindById("wnd[0]/tbar[0]/okcd");

targetFieldにTypeプロパティがあることがわかりました。

var tmp = targetField.Type;

これはGuiOkCodeFieldであることが判明しました。

したがって、必要なコードは次のとおりです。

((GuiOkCodeField)session.FindById("wnd[0]/tbar[0]/okcd")).Text= "InputText";

tldr; use((GuiOkCodeField)session.FindById( "wnd [0] / tbar [0] / okcd"))。Text = "InputText";

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

Related 関連記事

ホットタグ

アーカイブ