1

I'm writing a program in Oxygene .net There seems to be a problem with how I am handling nullable types

    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.

When I click the button firing the btnOK_Click event I get a strange error message

The runtime has encountered a fatal error. The address of the error was at 0x691886da, on thread 0x770. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.

4

3 回答 3

2

这看起来是编译器错误。我已经转发了 RemObjects 的信息,以便在此提交错误并修复它。与此同时,您可能会尝试更新版本(或者可能是beta 版)。

于 2013-04-18T17:59:55.687 回答
2

fwiw,我建议使用 Oxygene 内置的“可空”语言功能,因为它比 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;

无论如何,得到“运行时遇到致命错误”。表示编译器错误。我将使用您的测试用例在我们这边记录一个问题。

于 2013-04-18T17:59:46.763 回答
0

我相信解决方案是更换

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

Result := new System.Nullable<Double>;
于 2013-04-18T07:15:01.947 回答