• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 628
  • Last Modified:

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;
}
0
digitalwav
Asked:
digitalwav
  • 2
1 Solution
 
2266180Commented:
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;

0
 
JaccoCommented:
Here is my try

uses
  VarUtils, ActiveX;

function SyncFrameworkClientAPI: HRESULT;
var
  hr: HRESULT;
  pWrapper: ISCWrapper;
  pComponentDispatch: IDispatch;
  pComponent: ISCSyncComponent;
  vtEmpty: OleVariant;
  lSyncActivities: Integer;
  appname: OleVariant;
  lStatus: Integer;
begin
  hr := S_OK;
  VarClear(vtEmpty);
  hr := CoCreateInstance(CLSID_SCWrapper, nil, CLSCTX_ALL, ISCWrapper, pWrapper);
  if SUCCEEDED(hr) then
  begin
    // hr := hr or pWrapper.put_HideProgress(True);
    hr := hr or pWrapper.get_SyncComponent(SC_COMP_DATASYNC, pComponentDispatch);
    hr := hr or pComponentDispatch.QueryInterface(ISCSyncComponent, pComponent);
    lSyncActivities := SYNC_ACTIVITY_ALL;
    hr := hr or pComponent.put_Property(PROP_SyncActivities, lSyncActivities);
    appname := 'Darwin';
    lStatus := 0;
    hr := hr or pComponent.CallMethod(METHOD_AddAppToSync, 0, appname, EmptyParam, EmptyParam, lStatus);
    hr := hr or pWrapper.Sync(lStatus);
    hr := hr or pComponent.CallMethod(METHOD_ClearAppsToSync, 0, EmptyParam, EmptyParam, EmptyParam, lStatus);
    hr := hr or pWrapper.Sync(lStatus);
  end;
  Result := hr;
end;
0
 
JaccoCommented:
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
0
 
digitalwavIT Infrastructure ManagerAuthor Commented:
I will give these a shot today!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now