2011-12-13 79 views
0

所以我只是試圖從GUI線程顯示不同的線程窗體。對於我的生活中,我看不到正確的設置我的論據,這使我從捕獲錯誤消息的調用:參數計數不匹配與Windows窗體ShowDialog委託

「參數數量不匹配」

任何想法,我應該如何正確設置參數傳入?

#pragma once 
#include "ErrorSystemStop.h" 
using namespace System; 
using namespace System::Windows::Forms; 

delegate DialogResult ShowErrorWindow(System::Windows::Forms::IWin32Window^parentForm); 

void ThrowErrorWindow(System::String^ strErrorMessage, int iNumberOfSegments, System::Windows::Forms::IWin32Window^parentForm) 
{ 
//Only throw if we need too. 
if(!bErrorPause) 
{ 
    MainDisplay::ErrorSystemStop^stopMe = gcnew MainDisplay::ErrorSystemStop(strErrorMessage, iNumberOfSegments); 
    ShowErrorWindow^disp = gcnew ShowErrorWindow((System::Windows::Forms::Form ^)stopMe, &MainDisplay::ErrorSystemStop::ShowDialog); 
    stopMe->TopMost = true; 
    try 
    { 
     cli::array<System::Windows::Forms::IWin32Window ^>^Args = gcnew cli::array<System::Windows::Forms::IWin32Window ^>(1); 
     Args[0] = parentForm; 
     stopMe->Invoke(disp,(System::Windows::Forms::Form ^)stopMe, gcnew array<System::Object ^>{Args}); 
    } 
    catch(Exception ^e) 
    { 
     e->Message; 
    } 
} 
} //end ThrowErrorWindow 

我也試過:

array<Object^>^Args = {parentForm}; 
stopMe->Invoke(disp,(System::Windows::Forms::Form ^)stopMe, Args); 

謝謝

Alikar

回答

0

因此,原來我是路過的三個參數,我只是太累了,昨晚我沒有注意到。

我已經凝結的代碼到這一點:

delegate void ShowErrorWindow(ErrorThrowClass^form, System::String^ strErrorMessage, int iNumberOfSegments); 

void ThrowErrorWindow(System::String^ strErrorMessage, int iNumberOfSegments, System::Windows::Forms::Form^parentForm) 
{ 
//Only throw if we need too. 
if(!bErrorPause) 
{ 
    ShowErrorWindow^disp = gcnew ShowErrorWindow(&ErrorThrowClass::LaunchErrorWindow); 
    MthrControl(DataProtect,M_UNLOCK,M_DEFAULT); 
    try 
    { 
     array<Object^>^Args = {parentForm, strErrorMessage, iNumberOfSegments}; 
     parentForm->Invoke(disp, Args); 
    } 
    catch(Exception ^e) 
    { 
     e->Message; 
    } 
    MthrControl(DataProtect,M_LOCK,M_DEFAULT); 
} 
} //end Throw ErrorWindow 

代碼啓動其他錯誤窗口現在是在父GUI對象的靜態函數。這使得一切都可以在一個線程中啓動。