內的對象這從我的回答這個問答如下的參考:前往德爾福IDE
Can I change the display format for strings in the watch list?
事實證明,在D7和XE3,IDE的觀察的執行之間的某一點窗口從使用TListView更改爲TVirtualStringTree。
儘管我通過忽略VST並從剪貼板中獲取手錶值來發布了一個與XE4配合使用的答案的更新,但我仍然希望能夠從VST獲得手錶值。我想我知道如何做到這一點 一旦我有一個VST的參考,但問題是,我的嘗試讓一個失敗。
以下是我在自定義軟件包中使用的代碼的MCVE。希望它的功能是不言自明的。問題是代碼塊
if WatchWindow.Components[i] is TVirtualStringTree then begin
[...]
end;
從不執行,DESPITE出現在Memo1中的類名「TVirtualStringTree」。很明顯,該類名稱的組件未通過「is」測試。我猜測原因是編譯到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;
順便說一句,我認識到,依賴的IDE的實現細節的解決方案很可能是脆弱的,但是這僅僅是爲了娛樂(我喜歡這超出獲取字符串數據從一個組件的挑戰,其避免存儲的方式)。
VST版本不是唯一的問題。如果您的代碼使用與IDE不同的RTTI進行編譯,則「is」運算符會失敗,因此二進制文件中的VST組件與IDE中的VST組件不同。即使您的代碼使用完全相同的VST版本,RTTI仍然不匹配。這是運行時包發揮作用的地方。您的二進制文件必須鏈接到運行時軟件包,因此它與IDE共享相同的RTL,並且它必須鏈接到IDE用於其VST組件的相同軟件包。但是,如果VST直接編譯到IDE中並且不從包中導入,那麼您就是SOL ... –
...您將不得不放棄'is'運算符並使用'ClassName()'比較。這至少可以讓你檢測IDE的VST組件。但*訪問*它不會是安全的,除非你有相同的版本,所以內存佈局仍然匹配。 –
@RemyLebeau:謝謝。事實上,我試圖忽略「我」的結果,並在類名的基礎上強制轉換它,但是當我嘗試調用對象的方法時,會出現AV。 Fwiw,我在D7中使用了相同的「is」技術,其中Watch Window是一個TListView,並且在獲取參考和使用它方面工作良好。 – MartynA