Link to home
Start Free TrialLog in
Avatar of digitalwav
digitalwavFlag for United States of America

asked on

Convert C code to Delphi?

I'm having a tough time getting a method to work in Delphi. They have all the examples in C. Can you get me the delphi equivalent?

Thanks!


#include "ClientFW.h"
#include "ClientFW_i.c"
#include "ClientAPI.h"
#include "ClientAPI_i.c"
#include "../../DataSyncClientAPIDefines.h"
HRESULT CTestDlg::SyncFrameworkClientAPI()
{
HRESULT hr = S_OK;
CComPtr<ISCWrapper> pWrapper;
VARIANT vtEmpty;
::VariantInit(&vtEmpty);
if (SUCCEEDED(hr =
pWrapper.CoCreateInstance(CLSID_SCWrapper)))
{
//hr |= pWrapper->put_HideProgress(VARIANT_TRUE);
CComPtr<IDispatch> pComponentDispatch;
CComPtr<ISCSyncComponent> pComponent;
hr |= pWrapper->get_SyncComponent(SC_COMP_DATASYNC,
&pComponentDispatch);
hr |= pComponentDispatch.QueryInterface(&pComponent);
//
// Possible activities:
// SYNC_ACTIVITY_SYNCOUT
// SYNC_ACTIVITY_COMMUNICATE
// SYNC_ACTIVITY_SYNCIN
// SYNC_ACTIVITY_ALL
//
long lSyncActivities = SYNC_ACTIVITY_ALL;
hr |= pComponent-
>put_Property(CComBSTR(PROP_SyncActivities),
CComVariant(lSyncActivities));
// Sync for the specified application.
CComBSTR appname(_T("Darwin"));
long lStatus = 0;
hr |= pComponent

>CallMethod(CComBSTR(METHOD_AddAppToSync), 0,
&CComVariant(appname),
&vtEmpty, // DBID is optional
parameter
&vtEmpty,
&lStatus);
hr |= pWrapper->Sync(&lStatus);
// No applications specified means to sync all dbids for
all applications.
hr |= pComponent-
>CallMethod(CComBSTR(METHOD_ClearAppsToSync), 0,
&vtEmpty,
&vtEmpty,
&vtEmpty,
&lStatus);
hr |= pWrapper->Sync(&lStatus);
}
return hr;
}
Avatar of 2266180
2266180
Flag of United States of America image

seems that noone is trying :)

here is the little I can make out of it (considering that I never really wrote c++ applications, but have stumbled on c++ before)

uses activex; (among other stuff)

function CTestDlg.SyncFrameworkClientAPI: HRESULT;
var
  hr:hresult;
  pWrapper:  CComPtr<ISCWrapper> ;// dunno what this maps too
  vtEmpty:VARIANT;
  pComponentDispatch:CComPtr<IDispatch> ;// same as above
  pComponent:CComPtr<ISCSyncComponent> ;// same as above
  lSyncActivities:long;
  lStatus:long;
begin
  hr := S_OK;
  VariantInit(vtEmpty);
  hr := CoCreateInstance(CLSID_SCWrapper,some otehr parameters here);// look on the net if noone comes up with something. my COM is rather rusty and very basic
  if (SUCCEEDED(hr))
  begin
    //hr := hr or pWrapper->put_HideProgress(VARIANT_TRUE);
    hr := hr or pWrapper.get_SyncComponent(SC_COMP_DATASYNC, pComponentDispatch);
    hr := hr or pComponentDispatch.QueryInterface(pComponent);
//
// Possible activities:
// SYNC_ACTIVITY_SYNCOUT
// SYNC_ACTIVITY_COMMUNICATE
// SYNC_ACTIVITY_SYNCIN
// SYNC_ACTIVITY_ALL
//
    lSyncActivities := SYNC_ACTIVITY_ALL;
    hr := hr or pComponent.put_Property(CComBSTR(PROP_SyncActivities), CComVariant(lSyncActivities));
// the above casts mught not be necessary. but since I don't know the method signature I can't say
// Sync for the specified application.
CComBSTR appname(_T("Darwin")); // don't know what this means/does
    lStatus = 0;
    hr := hr or pComponent.CallMethod(CComBSTR(METHOD_AddAppToSync), 0,CComVariant(appname),
       vtEmpty, // DBID is optional
      parameter
      vtEmpty,
       lStatus);// the cast again mihgt not be necessary. also, since there was a &CComVariant(appname), that might be translated to a "var something" in the method signature. if so, then you'll need the exact datatype there and NO cast. if not, then you might not need cast.
    hr := hr or pWrapper.Sync(lStatus);
// No applications specified means to sync all dbids for all applications.
    hr := hr or pComponent.CallMethod(CComBSTR(METHOD_ClearAppsToSync), 0,
      vtEmpty,
      vtEmpty,
      vtEmpty,
      lStatus);
    hr := hr or pWrapper.Sync(lStatus);
  end;
  result:= hr;
end;

ASKER CERTIFIED SOLUTION
Avatar of Jacco
Jacco
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This compiles fine with the following assumptions:

const
  CLSID_SCWrapper: TGUID = '{8EF9540C-AD48-4739-A4EB-7027A7D624D2}';
  SC_COMP_DATASYNC = 1;
  SYNC_ACTIVITY_ALL = 0;
  PROP_SyncActivities = 'SomePropertyName';
  METHOD_AddAppToSync = 'MethodName';
  METHOD_ClearAppsToSync = 'MethodName';

type
  ISCWrapper = interface
  ['{DCCD1D4C-B14A-498F-866D-D6802AE3CEAD}']
    function put_HideProgress(Value: OleVariant): HRESULT;
    function get_SyncComponent(CompType: Integer; var Comp: IDispatch): HRESULT;
    function Sync(var lStatus: Integer): HRESULT;
  end;

  ISCSyncComponent = interface
  ['{B8F18CAF-71CD-488A-8414-F737079C55AD}']
    function put_Property(Name: OleVariant; Value: OleVariant): HRESULT;
    function CallMethod(Name: OleVariant; IntParam, AppName, Param1, Param2: OleVariant; var Status: Integer): HRESULT;
  end;

Regards Jacco
Avatar of digitalwav

ASKER

I will give these a shot today!