2017-11-07 10 views
0

私はC++ Builder Tokyo 10.2でMobile(AndroidとIOS)プロジェクトを持っています。 3つのフォームがありますが、すべてにはいくつかのTEditがあります。 各フォームには、それぞれ独自の「FormVirtualKeyboardShown」および「FormVirtualKeyboardHidden」機能があります。 そして、私はフォーカスされているTEditを取得するために、それぞれに「Focused-> GetObject()」(FormVirtualKeyboardShown関数)を持っています。C++ビルダーOnVirtualKeyboardShownとOnVirtualKeyboardHiddenから他のフォームを呼び出す

問題は次のとおりです。「FormVirtualKeyboardShown」のすべての機能は、どのフォームが呼び出していても発生しています。 .CPP、.H、.FMXファイルの関数の名前を変更しようとしましたが、関数の名前をすべてのプロジェクトに固有のものにしています。 しかし、まだ動作していません。すべての形式ですべての関数を呼び出しています。

そのため、dynamic_castコードを持つ行にエラーメッセージが表示されます。

--------------------------- 
Debugger Exception Notification 
--------------------------- 
Project Project1.apk raised exception class Segmentation fault (11). 

他のフォームからTEditを取得しようとすると、エラーが発生します。 私はFMXで新しいですし、私はそれのようなものを見たことがありません。

void __fastcall TForm3::FormVirtualKeyboardShown(TObject *Sender, bool KeyboardVisible,const TRect &Bounds) 
{ 
    int num; 
    TControl * LFocused = dynamic_cast<TControl*>(Focused->GetObject()); 
    num = LFocused->ComponentIndex; 
    ShowMessage("Index of TEdit from Form THREE is "+ IntToStr(num)); 
} 

私のポイントがあるUnit2.cpp

void __fastcall TForm2::FormVirtualKeyboardShown(TObject *Sender, bool KeyboardVisible,const TRect &Bounds) 
{ 
    int num; 
    TControl * LFocused = dynamic_cast<TControl*>(Focused->GetObject()); 
    num = LFocused->ComponentIndex; 
    ShowMessage("Index of TEdit from Form TWO is "+ IntToStr(num)); 
} 

Unit3.cpp

Unit1.cpp

void __fastcall TForm1::FormVirtualKeyboardShown(TObject *Sender, bool KeyboardVisible,const TRect &Bounds) 
{ 
    int num; 
    TControl * LFocused = dynamic_cast<TControl*>(Focused->GetObject()); 
    num = LFocused->ComponentIndex; 
    ShowMessage("Index of TEdit from Form ONE is "+ IntToStr(num)); 
} 

::私は知っている必要があり ここに私のコードの一部です。厳密にどのTEditがフォーカスであるか。だから私は適切に行動を取ることができます。

Unit1.cpp(Form1)でのみ、これらの機能(FormVirtualKeyboardShownとFormVirtualKeyboardHidden)を作成する必要がありますか。 したがって、別のフォームのすべてのTEditはForm1でこれらの関数を起動します。 もしそうなら...どのようなTEditにフォーカスがあるのか​​をどのように識別できますか?任意のフォームから???私はC++ Builderの10.2東京25.0.26309.314

を使用しています

私にみんなを助けてください! ありがとうございました!

+0

"* dyを持つ行にエラーメッセージが表示されるnamic_castコード* " - エラーが実際に何であるかは言わなかった。 –

答えて

0

複数のフォームが同じVirtualKeyboardイベントを同時に発生させる理由についてはコメントできません。 FireMonkeyのバグのように聞こえます。 KeyboardVisibleパラメータが1つのイベントでtrueであり、他の2つのイベントでfalseである場合は、奇妙なデザインの選択となります。

しかし、たとえそうであっても、これは、回避するにはかなり簡単でなければなりません。例:

void __fastcall TForm1::FormVirtualKeyboardShown(TObject *Sender, bool KeyboardVisible, const TRect &Bounds) 
{ 
    if (!KeyboardVisible) return; 
    _di_IControl ctrl = Focused; 
    if (!ctrl) return; 
    if (Screen->FocusControl != ctrl) return; 
    TControl * LFocused = static_cast<TControl*>(ctrl->GetObject()); 
    int num = LFocused->ComponentIndex; 
    ShowMessage("Index of TEdit from Form ONE is " + IntToStr(num)); 
} 

Unit2.cpp

void __fastcall TForm2::FormVirtualKeyboardShown(TObject *Sender, bool KeyboardVisible,const TRect &Bounds) 
{ 
    if (!KeyboardVisible) return; 
    _di_IControl ctrl = Focused; 
    if (!ctrl) return; 
    if (Screen->FocusControl != ctrl) return; 
    TControl * LFocused = static_cast<TControl*>(ctrl->GetObject()); 
    int num = LFocused->ComponentIndex; 
    ShowMessage("Index of TEdit from Form TWO is " + IntToStr(num)); 
} 

Unit3.cpp

void __fastcall TForm3::FormVirtualKeyboardShown(TObject *Sender, bool KeyboardVisible,const TRect &Bounds) 
{ 
    if (!KeyboardVisible) return; 
    _di_IControl ctrl = Focused; 
    if (!ctrl) return; 
    if (Screen->FocusControl != ctrl) return; 
    TControl * LFocused = static_cast<TControl*>(ctrl->GetObject()); 
    int num = LFocused->ComponentIndex; 
    ShowMessage("Index of TEdit from Form THREE is " + IntToStr(num)); 
} 

Unit1.cpp

+0

すばらしいレミそれは完璧に働いた。 本当にバグのようです。 関数は別のフォームから別の関数(同じ名前)をどのように呼び出すことができますか? 私はそれが同じ名前かもしれないと思った。 しかし、私が言ったように、私は変更しようとしましたが、それは仕事をしませんでした。 エラーメッセージの間違いをおかけして申し訳ありません。 投稿を編集してエラーメッセージを表示します。 ありがとうございました。 –

関連する問題