2011-11-13 5 views
4

TJSONObjectまたはTJSONValueのデバッガビジュアライザを作成しようとしています。私はビジュアライザーのほとんどがうまく働いています。私が抱えている問題は、TJSONObjectへの参照、または少なくともTJSONObjectのtostring()値への参照を取得することです。外部ビューアデバッガビジュアライザからオブジェクトまたはそのデータへの参照を取得するにはどうすればよいですか?

Jeremy Northの素晴らしい投稿、http://edn.embarcadero.com/article/40268によると、私はIOTADebuggerVisualizerExternalViewer実装のShowメソッドから必要なものを取得する必要があります。具体的には、Expression、TypeName、およびEvalResultの文字列パラメータから取得します。

私が理解しているところでは、Expressionは(視覚化された)検査される変数の名前であり、TypeNameは変数のクラス名であり、EvalResultは変数のデフォルトの文字列表現です。

私は簡単なテストのために、私はTFrameの子孫にTMemoを配置しました。 IOTADebuggerVisualizerExternalViewer.Showメソッドから、Expression、TypeName、およびEvalResultを渡す、私のTFrameのShowJSONObjectメソッドを呼び出します。関連するコードは、ここに表示されます:

function TDebuggerJSONVisualizer.Show(const Expression, TypeName, EvalResult: string; 
    SuggestedLeft, SuggestedTop: Integer): 
    IOTADebuggerVisualizerExternalViewerUpdater; 
var 
    AForm: TCustomForm; 
    AFrame: TJSONViewerFrame; 
    VisDockForm: INTACustomDockableForm; 
begin 
    VisDockForm := TJSONVisualizerForm.Create(Expression) as INTACustomDockableForm; 
    AForm := (BorlandIDEServices as INTAServices).CreateDockableForm(VisDockForm); 
    AForm.Left := SuggestedLeft; 
    AForm.Top := SuggestedTop; 
    (VisDockForm as IFrameFormHelper).SetForm(AForm); 
    AFrame := (VisDockForm as IFrameFormHelper).GetFrame as TJSONViewerFrame; 
    AFrame.ShowJSONObject(Expression, TypeName, EvalResult); 
    Result := AFrame as IOTADebuggerVisualizerExternalViewerUpdater; 
end; 

{ TStringListViewerFrame } 

procedure TJSONViewerFrame.ShowJSONObject(const Expression, TypeName, 
    EvalResult: string); 
begin 
    Memo1.Lines.Add(Expression); 
    Memo1.Lines.Add(TypeName); 
    Memo1.Lines.Add(EvalResult); 
end; 

あなたが見ることができるように、私はこの時点で私は私のShowJSONObject方法から、これらの3つのパラメータの値を表示しようとしています。ここで

は私がビジュアライザを使用して表示しようとしたシンプルなTJSONObjectです:

var 
jo: TJSONObject; 
begin 
    jo := TJSONObject.Create; 
    jo.AddPair('one', 'one'); 
    jo.AddPair('two', TJSONNumber.Create(1)); //a breakpoint here 

結果は次のようになります。

A debugger visualizer under development

私はEvalResultはのtoString表現を返すだろうと期待していましたTJSONObjectの中で、uninformative()を返しただけです。これは、ローカル変数ウィンドウにデフォルトで表示されるものと同じものです。

ビジュアライザが呼び出されたTJSONObjectのトーストリング表現または実際のオブジェクトのハンドルを取得して、その値を分解して表示する方法を教えてください。

答えて

3

あなたが(それはここで宣言されていないいくつかのローカル変数を使用することができますので、ちょうど私自身のビジュアライザソースからコピーされた)この手順を使用して(ToStringメソッドの呼び出しを含む)あなたの式を評価する必要があります。

function TJSONViewerFrame.Evaluate(Expression: string): string; 
var 
    CurProcess: IOTAProcess; 
    CurThread: IOTAThread; 
    ResultStr: array[0..4095] of Char; 
    CanModify: Boolean; 
    ResultAddr, ResultSize, ResultVal: LongWord; 
    EvalRes: TOTAEvaluateResult; 
    DebugSvcs: IOTADebuggerServices; 
begin 
    begin 
    Result := ''; 
    if Supports(BorlandIDEServices, IOTADebuggerServices, DebugSvcs) then 
     CurProcess := DebugSvcs.CurrentProcess; 
    if CurProcess <> nil then 
    begin 
     CurThread := CurProcess.CurrentThread; 
     if CurThread <> nil then 
     begin 
     EvalRes := CurThread.Evaluate(Expression, @ResultStr, Length(ResultStr), 
      CanModify, eseAll, '', ResultAddr, ResultSize, ResultVal, '', 0); 
     case EvalRes of 
      erOK: Result := ResultStr; 
      erDeferred: 
      begin 
       FCompleted := False; 
       FDeferredResult := ''; 
       FDeferredError := False; 
       FNotifierIndex := CurThread.AddNotifier(Self); 
       while not FCompleted do 
       DebugSvcs.ProcessDebugEvents; 
       CurThread.RemoveNotifier(FNotifierIndex); 
       FNotifierIndex := -1; 
       if not FDeferredError then 
       begin 
       if FDeferredResult <> '' then 
        Result := FDeferredResult 
       else 
        Result := ResultStr; 
       end; 
      end; 
      erBusy: 
      begin 
       DebugSvcs.ProcessDebugEvents; 
       Result := Evaluate(Expression); 
      end; 
     end; 
     end; 
    end; 
    end; 
end; 

だから今あなたのShow関数を次のようなものに置き換えることができます:

AFrame.ShowJSONObject(Expression, TypeName, Evaluate(Expression + '.ToString')); 
関連する問題