Gestione degli errori nei file HTML della Creazione guidata personalizzata
Aggiornamento: novembre 2007
Quando si crea una procedura guidata con un'interfaccia utente, il progetto include file HTM. Utilizzare questi file per personalizzare il progetto. Per ulteriori informazioni, vedere I file HTML.
È opportuno che il progetto includa la gestione degli errori. Di seguito è riportato un esempio di questo tipo di codice.
Per gestire gli errori in HTML
Quando si convalidano i campi, se si chiama un metodo di convalida in una DLL (che dovrebbe impostare le informazioni sugli errori), chiamare ReportError senza parametri.
function ValidateInput() { if (!window.external.ValidateFile(HEADER_FILE.value)) { ReportError(); HEADER_FILE.focus(); return false; } }
Quando si convalidano i campi, se si convalida un campo utilizzando solo lo script HTML, chiamare prima SetErrorInfo, quindi ReportError senza parametri.
function OnWhatever() { if (!ValidateInput()) window.external.ReportErrror(); .... } function ValidateInput() { ..... if (HEADER_FILE.value == IMPL_FILE.value) { var L_ErrMsg_Text = "Header and implementation files cannot have the same name."; SetErrorInfo(L_ErrMsg_Text); bValid = false; } if (TYPE.value == "") { var L_ErrMsg4_Text = "Type cannot be blank."; SetErrorInfo(L_ErrMsg4_Text); bValid = false; } return bValid; }
Chiamare ReportError con i parametri:
function ValidateInput() { if (!IsListed(strType)) { var L_Invalid2_Text = "The variable type should be one of the types listed."; window.external.ReportError(L_Invalid2_Text); VariableType.focus(); return false; } }
Se è necessario tornare alla finestra di dialogo Nuovo progetto o Aggiungi elemento, restituire VS_E_WIZBACKBUTTONPRESS:
try { oCM = window.external.ProjectObject.CodeModel; } catch(e) { var L_NCBError_Text = "Cannot access the Class View information (.ncb) file. Class View information will not be available."; window.external.ReportError(L_NCBError_Text); return VS_E_WIZARDBACKBUTTONPRESS;