以下是我对此问题的回答:
事实证明,在D7和XE3之间的某个时刻,IDE的Watch Window的实现从使用TListView变为TVirtualStringTree.
虽然我发布了一个更新我的答案,通过忽略VST并从剪贴板获取监视值来使用XE4,我仍然希望能够从VST获得监视值,如果可以的话.一旦我引用了VST,我想我知道怎么做,但问题是我尝试获取VST失败了.
以下是我在自定义包中使用的代码的MCVE.希望它的作用是不言自明的.问题是块中的代码
if WatchWindow.Components[i] is TVirtualStringTree then begin
[...]
end;
Run Code Online (Sandbox Code Playgroud)
从不执行,DESOPITE出现在Memo1中的类名"TVirtualStringTree".显然,具有该类名的组件未通过"是"测试.我猜测的原因是编译到IDE中的TVirtualTreeView是一个与我正在使用的版本不同的版本,v.5.3.0,这是我能找到的最接近XE4的前身.
所以,我的问题是,这是可能的解释,我能做些什么吗?我怀疑是否有人可以通过帽子来繁荣用于XE4的TVirtualStringTree版本,这可能会解决我的问题.
type
TOtaMenuForm = class(TForm)
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
private
WatchWindow : TForm;
VST : TVirtualStringTree;
end;
procedure TOtaMenuForm.FormCreate(Sender: TObject);
var
i : Integer;
S : String;
begin
WatchWindow := Nil;
VST := Nil;
// Iterate the IDE's forms to find the Watch Window
for i := 0 to Screen.FormCount - 1 do begin
S := Screen.Forms[i].Name;
if CompareText(S, 'WatchWindow') = 0 then begin
WatchWindow := Screen.Forms[i];
Break;
end;
end;
Assert(WatchWindow <> Nil);
if WatchWindow <> Nil then begin
Memo1.Lines.Add('Looking for VST');
for i := 0 to WatchWindow.ComponentCount - 1 do begin
Memo1.Lines.Add(IntToStr(i) + ':' + WatchWindow.Components[i].ClassName);
if WatchWindow.Components[i] is TVirtualStringTree then begin
VST := TVirtualStringTree(WatchWindow.Components[i]);
Memo1.Lines.Add('found VST');
Break;
end;
end;
if VST = Nil then
Memo1.Lines.Add('VST not found');
end;
end;
Run Code Online (Sandbox Code Playgroud)
顺便说一下,我意识到依赖于IDE的实现细节的解决方案可能很脆弱,但这只是为了娱乐(我喜欢从一个组件中获取字符串数据以避免存储任何内容的挑战).
归档时间: |
|
查看次数: |
184 次 |
最近记录: |