How do I add methods and properties?

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

    #1

    How do I add methods and properties?

    Hi everybody,

    Using Microsoft Visual C# 2005 Express Edition, I'm trying to create a
    class library (.dll) to include in a Delphi project.

    Since I'm new to building .dlls, I've searched the internet and am now
    following an example I've found at
    http://www.dotnetheaven.com/Uploadfi...14101AM/pr12.a
    spx , which explains how to build a .dll, and how to call it. So far so
    good.

    But when I come to the part of adding methods and properties, I'm asked
    to right-click on the class-name and select 'Add->Add Method' (or similar
    for properties), which is not available in the Express Edition! I've
    checked the internet again, and this is indeed not available in the EE.

    However, the Express Edition is the only edition I have, so I would
    really like to know how I can add these methods and properties myself,
    which I assume *is* possible (otherwise it would be rather daft to
    include the ability to create class libraries, imho).

    Would anybody please care to explain to me how I do this? Or point me in
    the right direction to a nice tutorial?

    Thanks in advance!

    Ikke
  • Peter Duniho

    #2
    Re: How do I add methods and properties?

    On Sat, 12 Jul 2008 15:10:07 -0700, Ikke <ikke@hier.bewr ote:
    [...]
    However, the Express Edition is the only edition I have, so I would
    really like to know how I can add these methods and properties myself,
    which I assume *is* possible (otherwise it would be rather daft to
    include the ability to create class libraries, imho).
    >
    Would anybody please care to explain to me how I do this? Or point me in
    the right direction to a nice tutorial?
    You can just type them in manually. Open the appropriate .cs file where
    the class is defined and add them yourself.

    In fact, I'm amazed anyone would even use the GUI to add a method or a
    property from scratch (as opposed to those required to implement an
    interface, override an existing method, etc. where the IDE has enough
    information to save some real typing). Such a feature adds so little
    value that I didn't even realize it existed in VS. :)

    Pete

    Comment

    • Barry Kelly

      #3
      Re: How do I add methods and properties?

      Ikke wrote:
      Using Microsoft Visual C# 2005 Express Edition, I'm trying to create a
      class library (.dll) to include in a Delphi project.
      What is your point of integration with Delphi? Using Delphi for .NET?
      (I work for CodeGear (now part of Embarcadero), on the Delphi compiler.)

      In any case, programming is mostly a text-based discipline. I wouldn't
      waste time with GUI/menus/etc. for writing new code. Here's a simple C#
      class library:

      ---8<---
      using System;
      public class MyClass
      {
      string _myProperty;

      public void MyMethod()
      {
      // a method
      Console.WriteLi ne("Current MyProperty: {0}", MyProperty);
      }

      public string MyProperty
      {
      get { return _myProperty; }
      set { _myProperty = value; }
      }
      }
      --->8---

      Save it as 'Lib.cs' and compile with 'csc /t:library Lib.cs', and you'll
      end up with a Lib.dll, a fresh new C# class library.

      Alternatively, replace the body of the main source file in your VS
      Express project with the above text, and compile from VS, and you'll get
      a similar result, albeit with a different name (based on your project
      name).

      Other details depend on your scenario.

      -- Barry

      --

      Comment

      • Todd Carnes

        #4
        Re: How do I add methods and properties?

        Peter Duniho wrote:
        On Sat, 12 Jul 2008 15:10:07 -0700, Ikke <ikke@hier.bewr ote:
        >
        >[...]
        >However, the Express Edition is the only edition I have, so I would
        >really like to know how I can add these methods and properties myself,
        >which I assume *is* possible (otherwise it would be rather daft to
        >include the ability to create class libraries, imho).
        >>
        >Would anybody please care to explain to me how I do this? Or point me in
        >the right direction to a nice tutorial?
        >
        You can just type them in manually. Open the appropriate .cs file where
        the class is defined and add them yourself.
        >
        In fact, I'm amazed anyone would even use the GUI to add a method or a
        property from scratch (as opposed to those required to implement an
        interface, override an existing method, etc. where the IDE has enough
        information to save some real typing). Such a feature adds so little
        value that I didn't even realize it existed in VS. :)
        >
        Pete
        I add methods, properties, etc. via the class diagram (which is also not
        available in the express edition) and I love it....but then I'm only a
        beginner and appreciate the GUI making sure I get it right the first time.

        To us "noobs" it adds a LOT of value, IMHO. :)

        Todd

        Comment

        • Todd Carnes

          #5
          Re: How do I add methods and properties?

          Ikke wrote:
          Hi everybody,
          >
          Using Microsoft Visual C# 2005 Express Edition, I'm trying to create a
          class library (.dll) to include in a Delphi project.
          >
          Since I'm new to building .dlls, I've searched the internet and am now
          following an example I've found at
          http://www.dotnetheaven.com/Uploadfi...14101AM/pr12.a
          spx , which explains how to build a .dll, and how to call it. So far so
          good.
          >
          But when I come to the part of adding methods and properties, I'm asked
          to right-click on the class-name and select 'Add->Add Method' (or similar
          for properties), which is not available in the Express Edition! I've
          checked the internet again, and this is indeed not available in the EE.
          >
          However, the Express Edition is the only edition I have, so I would
          really like to know how I can add these methods and properties myself,
          which I assume *is* possible (otherwise it would be rather daft to
          include the ability to create class libraries, imho).
          >
          Would anybody please care to explain to me how I do this? Or point me in
          the right direction to a nice tutorial?
          >
          Thanks in advance!
          >
          Ikke
          You're going to have to type them in by hand, which isn't really all
          that hard. :)

          Todd

          Comment

          • Ikke

            #6
            Re: How do I add methods and properties?

            "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in
            news:op.ud69d61 e8jd0ej@petes-computer.local:

            <snip>
            You can just type them in manually. Open the appropriate .cs file
            where the class is defined and add them yourself.
            >
            In fact, I'm amazed anyone would even use the GUI to add a method or a
            property from scratch (as opposed to those required to implement an
            interface, override an existing method, etc. where the IDE has enough
            information to save some real typing). Such a feature adds so little
            value that I didn't even realize it existed in VS. :)
            Thanks for the information, Peter. Since Barry and Todd basically gave me
            the same advice, I've gone ahead and tried it. But it doesn't work.

            I know I can type in the methods and properties myself, without using a
            GUI (and yes, I prefer it that way), but surely there must be some extra
            stuff that I'm missing here? If you just add a method, it doesn't mean it
            is exposed in the .dll as well, or does it?

            Anyway, here's my small example:

            --- C# code ---
            using System;
            using System.Collecti ons.Generic;
            using System.Text;


            namespace development
            {
            public class dev
            {
            public int Add(int val1, int val2)
            {
            return val1 + val2;
            }
            }
            }
            --- /C# code ---

            As you can see, a simple example (taken from one of the many pages I've
            found) with a simple function, adding two integers.

            Now, here's the Delphi code to call the .dll - first I've defined a
            function:
            function Add(val1, val2 : Integer) : Integer; stdcall; far; external
            'development.dl l';
            And I use said function as Add(1, 2); somewhere in my code.

            Everything compiles fine: C# compiles and builds me a .dll, and my Delphi
            project builds as well. But as soon as I try to run it, I get an access
            violation.

            I assume I need to 'expose' the methods I'm using in C# in my .dll
            somehow, but I don't know how...

            Is it even possible to call a .Net .dll like this?

            Thanks for any info!

            Ikke

            Comment

            • Ikke

              #7
              Re: How do I add methods and properties?

              Barry Kelly <barry.j.kelly@ gmail.comwrote in
              news:l3ei74d8ii 7dd1ubu6pr7t6ot 4393noud9@4ax.c om:
              Ikke wrote:
              >
              >Using Microsoft Visual C# 2005 Express Edition, I'm trying to create
              >a class library (.dll) to include in a Delphi project.
              >
              What is your point of integration with Delphi? Using Delphi for .NET?
              (I work for CodeGear (now part of Embarcadero), on the Delphi
              compiler.)
              <snip>

              We would like to write a small application, involving a 3D renderer. One
              of us is developing the renderer in C#, mainly because of the
              possibilities with the new XNA platform. However, the rest of us are
              more familiar with Delphi (not Delphi .Net), so we're trying to come up
              with some sort of interface.

              Basically, the main project will be a Delphi project, which calls one of
              two .dll's: - one .dll written in Delphi, which is a 'fake' renderer to
              allow us to test our code - one .dll written in C#, which is the real
              renderer.

              It looked really nice on paper :)

              Thanks,

              Ikke

              Comment

              • Todd Carnes

                #8
                Re: How do I add methods and properties?

                Ikke wrote:
                "Peter Duniho" <NpOeStPeAdM@nn owslpianmk.comw rote in
                news:op.ud69d61 e8jd0ej@petes-computer.local:
                >
                <snip>
                >You can just type them in manually. Open the appropriate .cs file
                >where the class is defined and add them yourself.
                >>
                >In fact, I'm amazed anyone would even use the GUI to add a method or a
                > property from scratch (as opposed to those required to implement an
                >interface, override an existing method, etc. where the IDE has enough
                >information to save some real typing). Such a feature adds so little
                >value that I didn't even realize it existed in VS. :)
                >
                Thanks for the information, Peter. Since Barry and Todd basically gave me
                the same advice, I've gone ahead and tried it. But it doesn't work.
                >
                I know I can type in the methods and properties myself, without using a
                GUI (and yes, I prefer it that way), but surely there must be some extra
                stuff that I'm missing here? If you just add a method, it doesn't mean it
                is exposed in the .dll as well, or does it?
                >
                Anyway, here's my small example:
                >
                --- C# code ---
                using System;
                using System.Collecti ons.Generic;
                using System.Text;
                >
                >
                namespace development
                {
                public class dev
                {
                public int Add(int val1, int val2)
                {
                return val1 + val2;
                }
                }
                }
                --- /C# code ---
                >
                As you can see, a simple example (taken from one of the many pages I've
                found) with a simple function, adding two integers.
                >
                Now, here's the Delphi code to call the .dll - first I've defined a
                function:
                function Add(val1, val2 : Integer) : Integer; stdcall; far; external
                'development.dl l';
                And I use said function as Add(1, 2); somewhere in my code.
                >
                Everything compiles fine: C# compiles and builds me a .dll, and my Delphi
                project builds as well. But as soon as I try to run it, I get an access
                violation.
                >
                I assume I need to 'expose' the methods I'm using in C# in my .dll
                somehow, but I don't know how...
                >
                Is it even possible to call a .Net .dll like this?
                >
                Thanks for any info!
                >
                Ikke
                >
                In .Net, after you make the dll, you have to go into the program that
                will be using it and add a reference to the dll. You also have to add a
                using statement to the new program so it will have access to the dll's
                namespace. In your example it would be "using development".

                Another thing that someone else here will have to confirm or deny,
                because I can't remember off the top of my head, but I think all the
                methods in the dll have to be declared as static.

                I'm not sure what the equivalent would be in Delphi. I've never messed
                with Delphi.

                Todd

                Comment

                • Peter Duniho

                  #9
                  Re: How do I add methods and properties?

                  On Sun, 13 Jul 2008 04:22:28 -0700, Ikke <ikke@hier.bewr ote:
                  [...]
                  Everything compiles fine: C# compiles and builds me a .dll, and my Delphi
                  project builds as well. But as soon as I try to run it, I get an access
                  violation.
                  >
                  I assume I need to 'expose' the methods I'm using in C# in my .dll
                  somehow, but I don't know how...
                  >
                  Is it even possible to call a .Net .dll like this?
                  I don't know. But I doubt it. Your .NET code _must_ run under the
                  managed .NET environment, and presumably your Delphi program doesn't run
                  under the managed .NET environment.

                  For what it's worth, I hope you can see how your original question was not
                  at all the question you actually wanted an answer for.

                  Pete

                  Comment

                  • Peter Duniho

                    #10
                    Re: How do I add methods and properties?

                    On Sun, 13 Jul 2008 07:41:32 -0700, Todd Carnes <toddcarnes@gma il.com>
                    wrote:
                    [...]
                    Another thing that someone else here will have to confirm or deny,
                    because I can't remember off the top of my head, but I think all the
                    methods in the dll have to be declared as static.
                    Not true. In fact, being able to only call static methods in a DLL would
                    make all of .NET pretty useless. Every instance member of a .NET class is
                    accessed from a .NET DLL.

                    Pete

                    Comment

                    • Barry Kelly

                      #11
                      Re: How do I add methods and properties?

                      Ikke wrote:
                      We would like to write a small application, involving a 3D renderer. One
                      of us is developing the renderer in C#, mainly because of the
                      possibilities with the new XNA platform. However, the rest of us are
                      more familiar with Delphi (not Delphi .Net), so we're trying to come up
                      with some sort of interface.
                      Ah, so you're going the COM interop route. I understand.

                      -- Barry

                      --

                      Comment

                      • cSharpLess

                        #12
                        Re: How do I add methods and properties?


                        "Ikke" <ikke@hier.beki rjoitti
                        viestissä:Xns9A DA89F8A52EFikke hierbe@69.16.17 6.253...
                        Barry Kelly <barry.j.kelly@ gmail.comwrote in
                        news:l3ei74d8ii 7dd1ubu6pr7t6ot 4393noud9@4ax.c om:
                        <snip>
                        the main project will be a Delphi project, which calls one of
                        two .dll's: - one .dll written in Delphi, which is a 'fake' renderer to
                        allow us to test our code - one .dll written in C#, which is the real
                        renderer.
                        Maybe http://interop.managed-vcl.com/netinterop_csharp.php help?

                        <snip>


                        Comment

                        • Todd Carnes

                          #13
                          Re: How do I add methods and properties?

                          Peter Duniho wrote:
                          On Sun, 13 Jul 2008 07:41:32 -0700, Todd Carnes <toddcarnes@gma il.com>
                          wrote:
                          >
                          >[...]
                          >Another thing that someone else here will have to confirm or deny,
                          >because I can't remember off the top of my head, but I think all the
                          >methods in the dll have to be declared as static.
                          >
                          Not true. In fact, being able to only call static methods in a DLL
                          would make all of .NET pretty useless. Every instance member of a .NET
                          class is accessed from a .NET DLL.
                          >
                          Pete
                          Thank you for clearing that up, Pete. Like I said, I'm still learning
                          and wasn't sure.

                          Todd

                          Comment

                          Working...