我需要在Delphi 7中使用IStorage
和IStream
接口。我需要IStorage實例中的存儲和流的名稱列表。如果我試圖收集他們是這樣的:如何檢查Delphi中枚舉的IStorage元素的類型?
procedure TStorageUtility.collectElementNamesByType(iStg_ : IStorage; names_ : TStringList; type_ : byte);
var
enum : IEnumSTATSTG;
rec : StatStg;
num : integer;
begin
if (iStg_.enumElements(0, NIL, 0, enum) = S_OK) then
while (enum.next(1, rec, @num) = S_OK) do
begin
if (rec.type = type_) then
names_.add(wideString(rec.pwcsName));
end;
end;
我得到一個編譯錯誤:
Identifier expected but 'TYPE' found
在該行
if (rec.type = type_) then
這裏是STATSTG記錄定義:https://msdn.microsoft.com/en-us/library/windows/desktop/aa380319(v=vs.85).aspx
如何在沒有任何編譯器錯誤信息的情況下檢查記錄類型?
您必須重命名該成員。您已將其定義爲'type:DWORD;'編譯器將其作爲新的'type'關鍵字。 – Victoria
@維多利亞我該怎麼做?這是一個Windows API類型。 – User007
不是。這只是Delphi中不允許的成員名稱。在轉角情況下,你可以用'&type:DWORD;'作爲前綴,但我會親自使用下劃線'type_:DWORD;' – Victoria