如何从外部查看器调试器可视化工具获取对象或其数据的引用?
我正在尝试为 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 方法中,我调用 TFrame 的 ShowJSONObject 方法,并向该方法传递 Expression、TypeName 和 EvalResult。相关代码显示在此处:
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 方法显示这三个参数的值。
这是我尝试使用可视化工具显示的一个简单的 TJSONObject:
var
jo: TJSONObject;
begin
jo := TJSONObject.Create;
jo.AddPair('one', 'one');
jo.AddPair('two', TJSONNumber.Create(1)); //a breakpoint here
结果如下所示:
I希望 EvalResult 能够返回 TJSONObject 的 tostring 表示形式,但它只返回无信息的 (),这与您在局部变量窗口中默认看到的内容相同。
如何获取调用可视化工具的 TJSONObject 的 tostring 表示形式或实际对象的句柄,以便可以解构并显示其值?
I am trying to write a debugger visualizer for a TJSONObject or a TJSONValue. I have most of the visualizer working nicely. The problem I am having is getting a reference to the TJSONObject, or at least to the tostring() value of the TJSONObject.
According to the samples I've seen, as well as the nice post by Jeremy North at http://edn.embarcadero.com/article/40268, I should get what I need from the Show method of my IOTADebuggerVisualizerExternalViewer implementation. Specifically, from the Expression, TypeName, and EvalResult string parameters.
From what I understand, Expression is the name of variable being inspected (visualized), TypeName is the classname of the variable, and EvalResult is the default string representation of the variable.
For a simple test I placed a TMemo on my TFrame descendant. From the IOTADebuggerVisualizerExternalViewer.Show method I call the ShowJSONObject method of my TFrame, to which I pass Expression, TypeName, and EvalResult. The relevant code appears here:
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;
As you can see, I at this point I am only trying to display the values of these three parameters from my ShowJSONObject method.
Here is a simple TJSONObject that I tried to display using the visualizer:
var
jo: TJSONObject;
begin
jo := TJSONObject.Create;
jo.AddPair('one', 'one');
jo.AddPair('two', TJSONNumber.Create(1)); //a breakpoint here
The result looks like this:
I was hoping that EvalResult would return the tostring representation of the TJSONObject, but it only returned the uninformative (), which is the same thing you see by default in the local variables window.
How do I get either the tostring representation of the TJSONObject for which the visualizer was invoked or a handle to the actual object, so I can deconstruct and display its value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用此过程来评估您的表达式(包括 ToString 调用)(刚刚从我自己的可视化工具源复制,因此它可以使用一些此处未声明的局部变量):
所以现在您可以将 Show 函数替换为如下所示:
You need to evaluate your expression (including ToString call) using this procedure (just copied from my own visualizer source so it could use some local variables that are not declared here):
So now you can replace your Show function with something like this: