2013-04-18 20 views
1

我寫在OXYGENE .NET 程序似乎要與如何我處理可空類型奇怪的CLR錯誤而OXYGENE .NET處理可空類型

namespace RULER; 

interface 

uses 
    System, 
    System.Drawing, 
    System.Collections, 
    System.Collections.Generic, 
    System.Windows.Forms, 
    System.ComponentModel; 

type 
    /// <summary> 
    /// Summary description for Settings. 
    /// </summary> 
    Settings = public partial class(System.Windows.Forms.Form) 
    private 
     method Settings_Shown(sender: System.Object; e: System.EventArgs); 
     method GetLowerBound : System.Nullable<Double>; 
     method SetLowerBound(lowerbound:System.Nullable<Double>); 
     method Settings_Load(sender: System.Object; e: System.EventArgs); 
     method btnOK_Click(sender: System.Object; e: System.EventArgs); 
    protected 
     method Dispose(aDisposing: Boolean); override; 
    public 
     property LowerBound : System.Nullable<Double> read GetLowerBound write SetLowerBound; 
    constructor; 
    end; 

implementation 

{$REGION Construction and Disposition} 
constructor Settings; 
begin 
    // 
    // Required for Windows Form Designer support 
    // 
    InitializeComponent(); 

    // 
    // TODO: Add any constructor code after InitializeComponent call 
    // 
end; 

method Settings.Dispose(aDisposing: Boolean); 
begin 
    if aDisposing then begin 
    if assigned(components) then 
     components.Dispose(); 

    // 
    // TODO: Add custom disposition code here 
    // 
    end; 
    inherited Dispose(aDisposing); 
end; 
{$ENDREGION} 

method Settings.Settings_Shown(sender: System.Object; e: System.EventArgs); 
begin 
    LowerBound := System.Nullable<Double>(Controller.configuration.LowerBound); 
end; 

method Settings.GetLowerBound : System.Nullable<Double>; 
begin 
    var bound : Double; 
    if Double.TryParse(txtLowerBound.Text, out bound) then 
    begin 
     Result := bound; 
    end else 
    begin 
     Result := System.Nullable<Double>(nil); 
    end; 
end; 

method Settings.SetLowerBound(lowerbound:System.Nullable<Double>); 
begin 
    if lowerbound.HasValue then 
    begin 
     txtLowerBound.Text := lowerbound.Value.ToString; 
    end else 
    begin 
     txtLowerBound.Text := ''; 
    end; 
end; 

method Settings.Settings_Load(sender: System.Object; e: System.EventArgs); 
begin 

end; 

method Settings.btnOK_Click(sender: System.Object; e: System.EventArgs); 
begin 
    var LB : System.Nullable<Double> := Self.GetLowerBound; 

    if LB.HasValue then 
    begin 
     Controller.configuration.LowerBound := LB.Value; 
    end; 
end; 

end. 

當我點擊按鈕的問題發射btnOK_Click事件我收到一條奇怪的錯誤消息

運行時遇到致命錯誤。錯誤 的地址位於線程0x770處的0x691886da處。錯誤代碼是0xc0000005。此 錯誤可能是CLR或用戶代碼的不安全或不可驗證部分中的錯誤。此錯誤的常見來源包括用戶 編組錯誤COM-interop或PInvoke,這可能會損壞 堆棧。

回答

2

FWIW,我會建議使用OXYGENE內置的 「可空」 的語言功能,因爲它的工作原理米UCH更透明並且比System.Nullable更直觀。例如:

method Settings.GetLowerBound : nullable Double; 
begin 
    var bound : Double; 
    if Double.TryParse(txtLowerBound.Text, out bound) then 
    begin 
     Result := bound; 
    end else 
    begin 
     Result := nil; 
    end; 
end; 

無論如何,得到「運行時遇到致命錯誤。」表示編譯器錯誤。我會用你的測試用例在我們身邊登錄一個問題。

0

我認爲解決辦法是更換

Result := System.Nullable<Double>(nil); 

隨着

Result := new System.Nullable<Double>; 
2

這看起來是一個編譯器錯誤。我已經將RemObjects的信息轉發到文件上並修正了這個問題。同時,您可以嘗試newer version(或者可能是beta)。

+0

以缺陷形式登錄我們的內部錯誤數據庫:// 61996:「運行時遇到致命錯誤。」可以爲空 – 2013-04-18 18:04:22

+0

哪裏是我未來提交錯誤報告的最佳位置? – sav 2013-04-19 01:49:08

+1

電子郵件支持@對於remobjects.com – 2013-04-19 15:01:27