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;
}
LVL 1
digitalwavIT Infrastructure ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.