1

Oxygene .net でプログラムを書いています null 許容型の扱い方に問題があるようです

    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 相互運用機能または PInvoke のユーザー マーシャリング エラーが含まれ、スタックが破損する可能性があります。

4

3 に答える 3

2

fwiw、Oxygene の組み込みの「nullable」言語機能を使用することをお勧めします。これは、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 に答える
2

これはコンパイル エラーのようです。RemObjects の情報を転送して、これに関するバグを報告し、修正しました。それまでの間、新しいバージョン(またはベータ版)を試すことができます。

于 2013-04-18T17:59:55.687 に答える
0

解決策は交換だと思います

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

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