digitalwav
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 "../../DataSyncClientAPIDe fines.h"
HRESULT CTestDlg::SyncFrameworkCli entAPI()
{
HRESULT hr = S_OK;
CComPtr<ISCWrapper> pWrapper;
VARIANT vtEmpty;
::VariantInit(&vtEmpty);
if (SUCCEEDED(hr =
pWrapper.CoCreateInstance( CLSID_SCWr apper)))
{
//hr |= pWrapper->put_HideProgress (VARIANT_T RUE);
CComPtr<IDispatch> pComponentDispatch;
CComPtr<ISCSyncComponent> pComponent;
hr |= pWrapper->get_SyncComponen t(SC_COMP_ DATASYNC,
&pComponentDispatch);
hr |= pComponentDispatch.QueryIn terface(&p Component) ;
//
// Possible activities:
// SYNC_ACTIVITY_SYNCOUT
// SYNC_ACTIVITY_COMMUNICATE
// SYNC_ACTIVITY_SYNCIN
// SYNC_ACTIVITY_ALL
//
long lSyncActivities = SYNC_ACTIVITY_ALL;
hr |= pComponent-
>put_Property(CComBSTR(PRO P_SyncActi vities),
CComVariant(lSyncActivitie s));
// Sync for the specified application.
CComBSTR appname(_T("Darwin"));
long lStatus = 0;
hr |= pComponent
>CallMethod(CComBSTR(METHO D_AddAppTo Sync), 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(METHO D_ClearApp sToSync), 0,
&vtEmpty,
&vtEmpty,
&vtEmpty,
&lStatus);
hr |= pWrapper->Sync(&lStatus);
}
return hr;
}
Thanks!
#include "ClientFW.h"
#include "ClientFW_i.c"
#include "ClientAPI.h"
#include "ClientAPI_i.c"
#include "../../DataSyncClientAPIDe
HRESULT CTestDlg::SyncFrameworkCli
{
HRESULT hr = S_OK;
CComPtr<ISCWrapper> pWrapper;
VARIANT vtEmpty;
::VariantInit(&vtEmpty);
if (SUCCEEDED(hr =
pWrapper.CoCreateInstance(
{
//hr |= pWrapper->put_HideProgress
CComPtr<IDispatch> pComponentDispatch;
CComPtr<ISCSyncComponent> pComponent;
hr |= pWrapper->get_SyncComponen
&pComponentDispatch);
hr |= pComponentDispatch.QueryIn
//
// Possible activities:
// SYNC_ACTIVITY_SYNCOUT
// SYNC_ACTIVITY_COMMUNICATE
// SYNC_ACTIVITY_SYNCIN
// SYNC_ACTIVITY_ALL
//
long lSyncActivities = SYNC_ACTIVITY_ALL;
hr |= pComponent-
>put_Property(CComBSTR(PRO
CComVariant(lSyncActivitie
// Sync for the specified application.
CComBSTR appname(_T("Darwin"));
long lStatus = 0;
hr |= pComponent
>CallMethod(CComBSTR(METHO
&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(METHO
&vtEmpty,
&vtEmpty,
&vtEmpty,
&lStatus);
hr |= pWrapper->Sync(&lStatus);
}
return hr;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This compiles fine with the following assumptions:
const
CLSID_SCWrapper: TGUID = '{8EF9540C-AD48-4739-A4EB- 7027A7D624 D2}';
SC_COMP_DATASYNC = 1;
SYNC_ACTIVITY_ALL = 0;
PROP_SyncActivities = 'SomePropertyName';
METHOD_AddAppToSync = 'MethodName';
METHOD_ClearAppsToSync = 'MethodName';
type
ISCWrapper = interface
['{DCCD1D4C-B14A-498F-866D -D6802AE3C EAD}']
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 -F737079C5 5AD}']
function put_Property(Name: OleVariant; Value: OleVariant): HRESULT;
function CallMethod(Name: OleVariant; IntParam, AppName, Param1, Param2: OleVariant; var Status: Integer): HRESULT;
end;
Regards Jacco
const
CLSID_SCWrapper: TGUID = '{8EF9540C-AD48-4739-A4EB-
SC_COMP_DATASYNC = 1;
SYNC_ACTIVITY_ALL = 0;
PROP_SyncActivities = 'SomePropertyName';
METHOD_AddAppToSync = 'MethodName';
METHOD_ClearAppsToSync = 'MethodName';
type
ISCWrapper = interface
['{DCCD1D4C-B14A-498F-866D
function put_HideProgress(Value: OleVariant): HRESULT;
function get_SyncComponent(CompType
function Sync(var lStatus: Integer): HRESULT;
end;
ISCSyncComponent = interface
['{B8F18CAF-71CD-488A-8414
function put_Property(Name: OleVariant; Value: OleVariant): HRESULT;
function CallMethod(Name: OleVariant; IntParam, AppName, Param1, Param2: OleVariant; var Status: Integer): HRESULT;
end;
Regards Jacco
ASKER
I will give these a shot today!
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.SyncFrameworkClie
var
hr:hresult;
pWrapper: CComPtr<ISCWrapper> ;// dunno what this maps too
vtEmpty:VARIANT;
pComponentDispatch:CComPtr
pComponent:CComPtr<ISCSync
lSyncActivities:long;
lStatus:long;
begin
hr := S_OK;
VariantInit(vtEmpty);
hr := CoCreateInstance(CLSID_SCW
if (SUCCEEDED(hr))
begin
//hr := hr or pWrapper->put_HideProgress
hr := hr or pWrapper.get_SyncComponent
hr := hr or pComponentDispatch.QueryIn
//
// Possible activities:
// SYNC_ACTIVITY_SYNCOUT
// SYNC_ACTIVITY_COMMUNICATE
// SYNC_ACTIVITY_SYNCIN
// SYNC_ACTIVITY_ALL
//
lSyncActivities := SYNC_ACTIVITY_ALL;
hr := hr or pComponent.put_Property(CC
// 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(CCom
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(CCom
vtEmpty,
vtEmpty,
vtEmpty,
lStatus);
hr := hr or pWrapper.Sync(lStatus);
end;
result:= hr;
end;