Einzelnen Beitrag anzeigen

ringli

Registriert seit: 7. Okt 2004
504 Beiträge
 
Delphi 11 Alexandria
 
#1

Übersetzen eines C++ Codeschnipsels nach Delphi

  Alt 4. Dez 2007, 13:45
Ich bräuchte mal eure Hilfe beim Übersetzen eines C++ Codeschnipsels nach Delphi. Eigentlich habe ich die Funktion schon übersetzt, allerdings bin ich mir nicht sicher ob das alles so richtig ist was ich da gemacht habe. Vor allem in der Zeile mit CreateInstance bin ich mir unsicher. Ausserdem erhalte ich beim Versuch zu Kompilieren zwei Fehlermeldungen vom Compiler (stehen im übersetzten Delphi-Code).

Orginaler C++ Quellcode:
Code:
class ATL_NO_VTABLE CConnect :
.
.
.
// Implementation
protected:
   // IDTFileSystem
   STDMETHOD(GetFileSystemSites)   (SAFEARRAY** ppFileSystemSites);

// Attribute
protected:
   // Site
   SC11::IDTFileSystemSitePtr   m_pFileSystemSite;               // Site
};

// Dateisysteme abfragen
STDMETHODIMP CConnect::GetFileSystemSites(SAFEARRAY** ppFileSystemSites)
{
   // Site muss erst erstellt werden
   if (NULL == m_pFileSystemSite)
   {
      // Site erstellen
      CComObject<CFileSystemSite>* pFileSystemSite;
      if (SUCCEEDED(CComObject<CFileSystemSite>::CreateInstance(&pFileSystemSite)))
      {
         // Site initialisieren
         pFileSystemSite->Initialize(m_pApplication, m_pAddInSettings);

         // Site initialisieren
         pFileSystemSite->QueryInterface(__uuidof(SC11::IDTFileSystemSite), (void**) &m_pFileSystemSite);
      }
   }

   // Site konnte nicht erstellt werden
   if (NULL == m_pFileSystemSite)
      return E_OUTOFMEMORY;

   // Grenzen fuer SafeArray
   SAFEARRAYBOUND rgsabound;
   rgsabound.lLbound = 0; rgsabound.cElements = 1;

   // SafeArray erstellen
   *ppFileSystemSites = SafeArrayCreate(VT_UNKNOWN, 1, &rgsabound);
   if (NULL == *ppFileSystemSites)
      return E_OUTOFMEMORY;

   // Zugriff auf das Array
   IUnknown** pItems = NULL;
   SafeArrayAccessData(*ppFileSystemSites, (void**) &pItems);
   
   // Interface abfragen
   m_pFileSystemSite->QueryInterface(__uuidof(SC11::IDTFileSystemSite), (void**) &pItems[0]);

   // Zugriff auf Array freigeben
   SafeArrayUnaccessData(*ppFileSystemSites);

   // Ans kloar
   return S_OK;
}
Übersetzter Delphi Quellcode:
Delphi-Quellcode:
type
  TConnect = class(...)
  protected
    // Site
    m_pFileSystemSite : IDTFileSystemSite;

    { Protected declarations }

    // IDTFileSystem
    function GetFileSystemSites(out ppFileSystemSites: PSafeArray): HResult; stdcall;
  end;

// Dateisysteme abfragen
function TConnect.GetFileSystemSites(out ppFileSystemSites: PSafeArray): HResult;
var
  pFileSystemSite : IInterface;
  rgsabound : SAFEARRAYBOUND;
  pItems : IUnknown;
begin
  Result := S_OK;

   // Site muss erst erstellt werden
   if m_pFileSystemSite = nil then
    begin
      pFileSystemSite := CreateComObject(IDTFileSystemSite);

      if pFileSystemSite <> nil then
        begin
          pFileSystemSite.QueryInterface(IDTFileSystemSite, m_pFileSystemSite);
        end;
    end;

   // Site konnte nicht erstellt werden
   if m_pFileSystemSite = nil then
    begin
        Result := E_OUTOFMEMORY;
    end;

   // Grenzen fuer SafeArray
   rgsabound.lLbound := 0; rgsabound.cElements := 1;

   // SafeArray erstellen
   ppFileSystemSites := SafeArrayCreate(VT_UNKNOWN, 1, rgsabound);
   if ppFileSystemSites = nil then
    begin
      Result := E_OUTOFMEMORY;
    end;

   // Zugriff auf das Array
   pItems := nil;
   // [DCC Fehler] Connect.pas(204): E2033 Die Typen der tatsächlichen und formalen Var-Parameter müssen übereinstimmen
   SafeArrayAccessData(ppFileSystemSites, pItems);

   // Interface abfragen
   // [DCC Fehler] Connect.pas(207): E2149 Klasse besitzt keine Standardeigenschaft
    m_pFileSystemSite.QueryInterface(IDTFileSystemSite, pItems[0]);

   // Zugriff auf Array freigeben
   SafeArrayUnaccessData(ppFileSystemSites);
end;
[edit=SirThornberry]code-tags durch c-tags ersetzt - Mfg, SirThornberry[/edit]
  Mit Zitat antworten Zitat