Board index » cppbuilder » Writing an OLE client with bcb for an OLE VB server

Writing an OLE client with bcb for an OLE VB server

We are rewriting all our applications in BCB 5 and we have a problem with
OLE in BCB and VB (Visual basic) :

This is a problem exemple with OLE

This is the VB OLE server code :
Public Function Test(ByRef Param1 As String, ByRef Param2 As String) As
String
    Dim Tmp As String
    MsgBox Param1
    MsgBox Param2
    Tmp = Param1
    Param1 = Param2
    Param2 = Tmp
    Test = "Succes"
End Function

This is the C++ Builder5 Client code :
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Variant V = CreateOleObject("Test.Serveur");
  Variant Param1("P1");
  Variant Param2("P2");
  Variant Res;
  Res = V.OleFunction("Test",Param1,Param2);
  ShowMessage(Res);
  ShowMessage(Param1);
  ShowMessage(Param2);

Quote
}

When i click the C++ app button :
Msgbox Param1 show nothing    // !
Msgbox Param2 show nothing    // !

ShowMessage(Rep) show "Succes"  // Ok
ShowMessage(Param1) show P1     // !
ShowMessage(Param2) show P2    //  !

If i write a VB OLE Client with this code everything is OK :
Private Sub Command1_Click()
    Dim Obj As Object
    Dim Param1 As String
    Dim Param2 As String
    Dim Res As String
    Set Obj = CreateObject("Test.Serveur")
    Param1 = "P1"
    Param2 = "P2"
    Res = Obj.Test(Param1, Param2)
    MsgBox Res
    MsgBox Param1
    MsgBox Param2
End Sub

MsgBox Param1 show "P1" // Ok
MsgBox Param2 show "P2" // Ok
MsgBox Res show "Succes" // Ok
Msgbox Param1 show "P2"  // Ok
Msgbox Param2 show "P1"  // Ok

Thanks for your Help

Charles Bosquet APISoft FRANCE

 

Re:Writing an OLE client with bcb for an OLE VB server


Charles Bosquet <cbosq...@free.fr> a crit dans le message :
L2Q%4.2175$ms.5212...@nnrp4.proxad.net...

Quote
> We are rewriting all our applications in BCB 5 and we have a problem with
> OLE in BCB and VB (Visual basic) :

> This is a problem exemple with OLE

> This is the VB OLE server code :
> Public Function Test(ByRef Param1 As String, ByRef Param2 As String) As
> String
>     Dim Tmp As String
>     MsgBox Param1
>     MsgBox Param2
>     Tmp = Param1
>     Param1 = Param2
>     Param2 = Tmp
>     Test = "Succes"
> End Function

> This is the C++ Builder5 Client code :
> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
>   Variant V = CreateOleObject("Test.Serveur");
>   Variant Param1("P1");
>   Variant Param2("P2");
>   Variant Res;
>   Res = V.OleFunction("Test",Param1,Param2);
>   ShowMessage(Res);
>   ShowMessage(Param1);
>   ShowMessage(Param2);
> }

> When i click the C++ app button :
> Msgbox Param1 show nothing    // !
> Msgbox Param2 show nothing    // !

> ShowMessage(Rep) show "Succes"  // Ok
> ShowMessage(Param1) show P1     // !
> ShowMessage(Param2) show P2    //  !

> If i write a VB OLE Client with this code everything is OK :
> Private Sub Command1_Click()
>     Dim Obj As Object
>     Dim Param1 As String
>     Dim Param2 As String
>     Dim Res As String
>     Set Obj = CreateObject("Test.Serveur")
>     Param1 = "P1"
>     Param2 = "P2"
>     Res = Obj.Test(Param1, Param2)
>     MsgBox Res
>     MsgBox Param1
>     MsgBox Param2
> End Sub

> MsgBox Param1 show "P1" // Ok
> MsgBox Param2 show "P2" // Ok
> MsgBox Res show "Succes" // Ok
> Msgbox Param1 show "P2"  // Ok
> Msgbox Param2 show "P1"  // Ok

> Thanks for your Help

> Charles Bosquet APISoft FRANCE

The corect C++ Builder5 Client code is :
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Variant V = CreateOleObject("Test.Serveur");
  WideString Param1("P1");
  WideString Param2("P2");
  Variant Res;
  Res = V.OleFunction("Test",&Param1,&Param2);
  ShowMessage(Res);
  ShowMessage(Param1);
  ShowMessage(Param2);

- Show quoted text -

Quote
}

Other Threads