0

I need to work with IStorage and IStream interfaces in Delphi 7. I need the name list of storages and streams in IStorage instances. If I try to collect them like this:

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;

I get a compiler error:

Identifier expected but 'TYPE' found

at the line

if ( rec.type = type_ ) then

Here is the STATSTG record definition : https://msdn.microsoft.com/en-us/library/windows/desktop/aa380319(v=vs.85).aspx

How can I check the record type without any compiler error message?

User007
  • 187
  • 10
  • You must rename that member. You have defined it like `type: DWORD;` which compiler takes as a new `type` keyword. – Victoria Jun 14 '17 at 11:23
  • @Victoria How can I do it? This is a Windows API type. – User007 Jun 14 '17 at 11:25
  • No. It's just a name of a member that is not allowed in Delphi. In corner case you can prefix it like `&type: DWORD;`, but I would personally use e.g. underscore `type_: DWORD;` – Victoria Jun 14 '17 at 11:25
  • @Victoria I thought `STATSTG` is Win API type, not the `type` field. – User007 Jun 14 '17 at 11:27
  • Yes, `StatStg` is a WinAPI structure which (I don't know how) got translated like that. In your code you should find something like `StatStg = record` where one of this structure members is declared as `type: DWORD;` and that's what is not allowed. That member must be renamed. – Victoria Jun 14 '17 at 11:30
  • @Victoria I found the reason. I just checked the MSDN documentation when I wrote my code and not the ActiveX unit which defines this type. `Type` is a keyword in Delphi so this field called dwType in this language. – User007 Jun 14 '17 at 11:45
  • 1
    Sorry, I missed that you mention line that fails. In case the structure member would be named `type`, the line with that structure definition would be the source of compilation failure. And it's not "in this language". You just cannot use name `type` (at most `&type` so the code from your question would be compilable - that `&` is an escape char for keywords; but do not do that), so the hungarian notation `dwType` was used. – Victoria Jun 14 '17 at 12:02

1 Answers1

1

OK. The MSDN documentation (for Delphi users) is misleading. This field of STATSTG is defined in the ActiveX unit by name dwType. When I use it, it compiles, of course.

User007
  • 187
  • 10
  • 1
    The documentation is not misleading. The field really is named `type` in the SDK. Delphi is the one that is being misleading, by renaming the field to work around a language limitation, as `type` is a reserved keyword. – Remy Lebeau Jun 14 '17 at 15:21
  • Didn't and won't try, but would a name of `&type` have worked, instead of `dwType`? – Rudy Velthuis Jun 14 '17 at 21:22
  • @Rudy, [it should](http://docwiki.embarcadero.com/RADStudio/en/Fundamental_Syntactic_Elements#Extended_Identifiers) but I would not modify an imported unit (if not necessary). I said that in comments above ;) – Victoria Jun 15 '17 at 00:03
  • @Victoria: neither would I. I was just wondering if that had been a possibility for Embarcadero's translators. – Rudy Velthuis Jun 15 '17 at 01:57