Delphi client / VS 2003 COM Server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • glenn

    Delphi client / VS 2003 COM Server

    I've gotten a COM server written in C# and I can call it from a VBScript
    just fine and it works perfectly. However, I import it into Delphi 6 or
    Delphi 2005 and I can not get access to any of the functions that are in the
    server. Is there something specific that I need to do in order to get
    Delphi to see the functions that are a part of the server?

    Thanks,

    glenn


  • Willy Denoyette [MVP]

    #2
    Re: Delphi client / VS 2003 COM Server


    "glenn" <ghancock@softe ksoftware.com> wrote in message
    news:ubWsNH6PFH A.2876@TK2MSFTN GP10.phx.gbl...[color=blue]
    > I've gotten a COM server written in C# and I can call it from a VBScript
    > just fine and it works perfectly. However, I import it into Delphi 6 or
    > Delphi 2005 and I can not get access to any of the functions that are in
    > the
    > server. Is there something specific that I need to do in order to get
    > Delphi to see the functions that are a part of the server?
    >
    > Thanks,
    >
    > glenn
    >
    >[/color]

    Don't know what the problem is or what should be done when using Delphi, but
    I suggest you go through the tutorials in MSDN first,

    - COM Interop Part 1: C# Client Tutorial
    - COM Interop Part 2: C# Server Tutorial

    and import the Server built in part 2 in Delphi.

    Willy.








    Comment

    • Philip Hristov

      #3
      Re: Delphi client / VS 2003 COM Server

      Hi,

      How do you call the COM server from Delphi (I assume Delphi for Win32)?
      In Delphi a COM server is called like this:

      Uses ComObj;

      Var
      MyServer: Variant;
      Begin
      MyServer := CreateOleObject ('ServerName');
      MyServer.YourMe thod(Param1, Param2);
      End;

      Call your server like this and tell us if this work. I am not so sure
      (I stopped coding for Win32 before year and a half) but I think the
      only way to call COM server (OLE Automation) is this way). I made one
      OLE server and then I called its methods from other program, but that
      was before years in Delphi 3...

      Greetings,

      Philip.

      Comment

      • glenn

        #4
        Re: Delphi client / VS 2003 COM Server

        Actually that is correct, however, you can also just drop the component that
        is created when you import the type library onto a form and it handles the
        create for you. I do this all the time so I know this method works just as
        well. The problem however, is that when I create the component and then
        attempt to access its properties, I can not see the properties and get
        errors when I compile. This is not normal for delphi and COM objects.

        I am trying a little test now and will let you know how it goes shortly...
        I am attempting to manually specify that the functions be visible to COm to
        see if it fixes my problem...

        Be back in a second... :-)

        glenn

        "Philip Hristov" <phristov83@gma il.com> wrote in message
        news:1113343134 .169775.240680@ f14g2000cwb.goo glegroups.com.. .[color=blue]
        > Hi,
        >
        > How do you call the COM server from Delphi (I assume Delphi for Win32)?
        > In Delphi a COM server is called like this:
        >
        > Uses ComObj;
        >
        > Var
        > MyServer: Variant;
        > Begin
        > MyServer := CreateOleObject ('ServerName');
        > MyServer.YourMe thod(Param1, Param2);
        > End;
        >
        > Call your server like this and tell us if this work. I am not so sure
        > (I stopped coding for Win32 before year and a half) but I think the
        > only way to call COM server (OLE Automation) is this way). I made one
        > OLE server and then I called its methods from other program, but that
        > was before years in Delphi 3...
        >
        > Greetings,
        >
        > Philip.
        >[/color]


        Comment

        • glenn

          #5
          Re: Delphi client / VS 2003 COM Server

          nope, didn't change anything at all. From delphi's perspective it sees the
          type library, it imports it just fine and adds a component to the pallet for
          the item. I then choose the component and drop to the form just like with
          any of my other COM objects. However, with other COM components I can view
          the properties and methods of the COM object just as though it were a class
          inside Delphi, but with the C# VS 2003 COM object, I can not see any methods
          or properties listed.

          its like I've created a COM object that has not methods exported and
          therefore they can not be seen. In all other languages I've written COM
          objects in, I've had to select specific functions that I wanted to export so
          that other programs could use and see just those items I selected. The way
          this looks, the entire program along with all its functions are suppose to
          be visible, but in fact I can't use them from Delphi. I can from VBScript
          but as that is the only NON VS program type language available on my
          computer I really can't test with anything else.

          Any ideas?

          Thanks,

          glenn


          "Philip Hristov" <phristov83@gma il.com> wrote in message
          news:1113343134 .169775.240680@ f14g2000cwb.goo glegroups.com.. .[color=blue]
          > Hi,
          >
          > How do you call the COM server from Delphi (I assume Delphi for Win32)?
          > In Delphi a COM server is called like this:
          >
          > Uses ComObj;
          >
          > Var
          > MyServer: Variant;
          > Begin
          > MyServer := CreateOleObject ('ServerName');
          > MyServer.YourMe thod(Param1, Param2);
          > End;
          >
          > Call your server like this and tell us if this work. I am not so sure
          > (I stopped coding for Win32 before year and a half) but I think the
          > only way to call COM server (OLE Automation) is this way). I made one
          > OLE server and then I called its methods from other program, but that
          > was before years in Delphi 3...
          >
          > Greetings,
          >
          > Philip.
          >[/color]


          Comment

          • glenn

            #6
            Re: Delphi client / VS 2003 COM Server

            Willy,[color=blue]
            > - COM Interop Part 1: C# Client Tutorial
            > - COM Interop Part 2: C# Server Tutorial
            >[/color]

            I have already reviewed and tried the sample programs that you suggest here
            and they don't work either. In fact they just add to the confusion for me
            as they are completely different than what the book on COM gives as
            tutorials for this subject. I am convienced that something has to be done
            here to expose these functions to other program languages that run in
            unmangaged code, however, I do not see how this is to be done yet...

            Any help would be appreciated...

            glenn


            Comment

            • Philip Hristov

              #7
              Re: Delphi client / VS 2003 COM Server

              I saw you mentioned Delphi 2005? Why do not to try to use the COM
              component in Delphi For .NET? Import it to the project like in VS, it
              will create an interop library. At least you will know if the problem
              is in Delphi or in the COM component.

              And one more thing, as you say COM component component you mean .NET
              Control which you registered with regasm.exe? Or you have created just
              COM Interface (no component only class with methods)?

              Philip.

              Comment

              • glenn

                #8
                Re: Delphi client / VS 2003 COM Server

                No, I used regasm to register and create the type library and then I
                imported into Delphi. Once Delphi imports the library, it creates the
                component on the pallet for the object. From there everything is very
                simple to use in Delphi, usually.

                And I hate to say it, but I have not tried to do it with Delphi 2005 because
                that won't solve my problem. I do not like Delphi 2005 and as a result I am
                having to determine if I can write some of our solutions with Visual Studio.
                However, this is a must to figure out in order to be able to do this. If I
                can not get COM to work properly with .NET in VS then I will be forced to
                continue to use Delphi 6 for all our solutions.

                Thanks,

                glenn


                "Philip Hristov" <phristov83@gma il.com> wrote in message
                news:1113347743 .448130.133910@ f14g2000cwb.goo glegroups.com.. .[color=blue]
                > I saw you mentioned Delphi 2005? Why do not to try to use the COM
                > component in Delphi For .NET? Import it to the project like in VS, it
                > will create an interop library. At least you will know if the problem
                > is in Delphi or in the COM component.
                >
                > And one more thing, as you say COM component component you mean .NET
                > Control which you registered with regasm.exe? Or you have created just
                > COM Interface (no component only class with methods)?
                >
                > Philip.
                >[/color]


                Comment

                • Doug Forster

                  #9
                  Re: Delphi client / VS 2003 COM Server

                  Hi Glenn,

                  Well I have no experience with writing managed COM servers but I had no real
                  problem getting a variation of the sample to work via Delphi 6.
                  Firstly if you import the type library there is a dependency on mscoree that
                  does not wrap correctly due to Delphi being CI. You can manually modify the
                  wrapper to fix this. If you use the designer to create your client interface
                  object then you must explicitly cast it to your interface to get to the
                  correct interface or alternatively Philips suggestion using late binding
                  also works fine, but you might need to scout around the registry to find the
                  class name that VS generates.

                  These worked:


                  procedure TForm1.Button1C lick(Sender: TObject);
                  Var
                  MyServer: Variant;
                  Begin
                  (InterfaceImple mentation1.Defa ultInterface as
                  IManagedInterfa ce).PrintHi('He llo world');
                  MyServer := CreateOleObject ('CSharpServer. InterfaceImplem entation');
                  MyServer.PrintH i('Hello world');
                  End;

                  [color=blue]
                  > However, this is a must to figure out in order to be able to do this. If
                  > I
                  > can not get COM to work properly with .NET in VS then I will be forced to
                  > continue to use Delphi 6 for all our solutions.[/color]

                  These problems are only minor as far as I can see.

                  Cheers
                  Doug Forster


                  Comment

                  • Philip Hristov

                    #10
                    Re: Delphi client / VS 2003 COM Server

                    Nice work Doug!

                    Greetings,

                    Philip.

                    Comment

                    • Willy Denoyette [MVP]

                      #11
                      Re: Delphi client / VS 2003 COM Server


                      "glenn" <ghancock@softe ksoftware.com> wrote in message
                      news:eOXOCU7PFH A.2876@TK2MSFTN GP10.phx.gbl...[color=blue]
                      > Willy,[color=green]
                      >> - COM Interop Part 1: C# Client Tutorial
                      >> - COM Interop Part 2: C# Server Tutorial
                      >>[/color]
                      >
                      > I have already reviewed and tried the sample programs that you suggest
                      > here
                      > and they don't work either. In fact they just add to the confusion for me
                      > as they are completely different than what the book on COM gives as
                      > tutorials for this subject. I am convienced that something has to be done
                      > here to expose these functions to other program languages that run in
                      > unmangaged code, however, I do not see how this is to be done yet...
                      >
                      > Any help would be appreciated...
                      >
                      > glenn
                      >
                      >[/color]

                      These samples work with VB, C++, VBScript native COM clients, seems like
                      Delphi has a problem importing the typelib created by regasm.

                      Willy.


                      Comment

                      • glenn

                        #12
                        Re: Delphi client / VS 2003 COM Server

                        Doug,

                        Thanks, I'll try that out and see if its my problem. I am also suspecting
                        Delphi here but just not sure what to do since it has never had a problem
                        like this before with any other COM server i've used.

                        Thanks,

                        glenn


                        "Doug Forster" <doug_ZAPTHIS_A T_ZAPTHIS_TONIQ _DOT_CO_DOT_NZ> wrote in
                        message news:eXEvrC9PFH A.1392@TK2MSFTN GP10.phx.gbl...[color=blue]
                        > Hi Glenn,
                        >
                        > Well I have no experience with writing managed COM servers but I had no[/color]
                        real[color=blue]
                        > problem getting a variation of the sample to work via Delphi 6.
                        > Firstly if you import the type library there is a dependency on mscoree[/color]
                        that[color=blue]
                        > does not wrap correctly due to Delphi being CI. You can manually modify[/color]
                        the[color=blue]
                        > wrapper to fix this. If you use the designer to create your client[/color]
                        interface[color=blue]
                        > object then you must explicitly cast it to your interface to get to the
                        > correct interface or alternatively Philips suggestion using late binding
                        > also works fine, but you might need to scout around the registry to find[/color]
                        the[color=blue]
                        > class name that VS generates.
                        >
                        > These worked:
                        >
                        >
                        > procedure TForm1.Button1C lick(Sender: TObject);
                        > Var
                        > MyServer: Variant;
                        > Begin
                        > (InterfaceImple mentation1.Defa ultInterface as
                        > IManagedInterfa ce).PrintHi('He llo world');
                        > MyServer := CreateOleObject ('CSharpServer. InterfaceImplem entation');
                        > MyServer.PrintH i('Hello world');
                        > End;
                        >
                        >[color=green]
                        > > However, this is a must to figure out in order to be able to do this.[/color][/color]
                        If[color=blue][color=green]
                        > > I
                        > > can not get COM to work properly with .NET in VS then I will be forced[/color][/color]
                        to[color=blue][color=green]
                        > > continue to use Delphi 6 for all our solutions.[/color]
                        >
                        > These problems are only minor as far as I can see.
                        >
                        > Cheers
                        > Doug Forster
                        >
                        >[/color]


                        Comment

                        • glenn

                          #13
                          Re: Delphi client / VS 2003 COM Server

                          Doug,

                          I must be missing something. I've copied your code exactly and also have
                          the same app setup exactly as the tutorial. However, when I run my delphi
                          exe, I get no errors, but I also get no results. It just passes over the
                          line for the COm server and moves on...
                          (InterfaceImple mentation1.Defa ultInterface as
                          IManagedInterfa ce).PrintHi('He llo World');

                          Again, no compile errors and no errors at run time, but no results when
                          running the above line. I also tried the second method using the variant
                          but it results in same thing... Any ideas what i might be doing wrong here?

                          Thanks,

                          glenn


                          "Doug Forster" <doug_ZAPTHIS_A T_ZAPTHIS_TONIQ _DOT_CO_DOT_NZ> wrote in
                          message news:eXEvrC9PFH A.1392@TK2MSFTN GP10.phx.gbl...[color=blue]
                          > Hi Glenn,
                          >
                          > Well I have no experience with writing managed COM servers but I had no[/color]
                          real[color=blue]
                          > problem getting a variation of the sample to work via Delphi 6.
                          > Firstly if you import the type library there is a dependency on mscoree[/color]
                          that[color=blue]
                          > does not wrap correctly due to Delphi being CI. You can manually modify[/color]
                          the[color=blue]
                          > wrapper to fix this. If you use the designer to create your client[/color]
                          interface[color=blue]
                          > object then you must explicitly cast it to your interface to get to the
                          > correct interface or alternatively Philips suggestion using late binding
                          > also works fine, but you might need to scout around the registry to find[/color]
                          the[color=blue]
                          > class name that VS generates.
                          >
                          > These worked:
                          >
                          >
                          > procedure TForm1.Button1C lick(Sender: TObject);
                          > Var
                          > MyServer: Variant;
                          > Begin
                          > (InterfaceImple mentation1.Defa ultInterface as
                          > IManagedInterfa ce).PrintHi('He llo world');
                          > MyServer := CreateOleObject ('CSharpServer. InterfaceImplem entation');
                          > MyServer.PrintH i('Hello world');
                          > End;
                          >
                          >[color=green]
                          > > However, this is a must to figure out in order to be able to do this.[/color][/color]
                          If[color=blue][color=green]
                          > > I
                          > > can not get COM to work properly with .NET in VS then I will be forced[/color][/color]
                          to[color=blue][color=green]
                          > > continue to use Delphi 6 for all our solutions.[/color]
                          >
                          > These problems are only minor as far as I can see.
                          >
                          > Cheers
                          > Doug Forster
                          >
                          >[/color]


                          Comment

                          • Philip Hristov

                            #14
                            Re: Delphi client / VS 2003 COM Server

                            Glenn,

                            Do it with CreateOleObject .

                            Philip.

                            Comment

                            • glenn

                              #15
                              Re: Delphi client / VS 2003 COM Server

                              Actually the previous code was working. I just realized that the C# example
                              was writing to console and I changed it to a messagebox since I'm testing
                              with a Delphi Win form. its now popping up the messagebox perfectly. I am
                              very excited now and can start laying out this project. Thanks for all the
                              help guys...

                              glenn


                              "Philip Hristov" <phristov83@gma il.com> wrote in message
                              news:1113404862 .364814.89890@g 14g2000cwa.goog legroups.com...[color=blue]
                              > Glenn,
                              >
                              > Do it with CreateOleObject .
                              >
                              > Philip.
                              >[/color]


                              Comment

                              Working...