By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,670 Members | 1,431 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,670 IT Pros & Developers. It's quick & easy.

How do I add methods and properties?

P: n/a
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
Jul 12 '08 #1
Share this Question
Share on Google+
12 Replies


P: n/a
On Sat, 12 Jul 2008 15:10:07 -0700, Ikke <ik**@hier.bewrote:
[...]
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
Jul 12 '08 #2

P: n/a
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.WriteLine("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

--
http://barrkel.blogspot.com/
Jul 12 '08 #3

P: n/a
Peter Duniho wrote:
On Sat, 12 Jul 2008 15:10:07 -0700, Ikke <ik**@hier.bewrote:
>[...]
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
Jul 13 '08 #4

P: n/a
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

Jul 13 '08 #5

P: n/a
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in
news:op***************@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.Collections.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.dll';
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

Jul 13 '08 #6

P: n/a
Barry Kelly <ba***********@gmail.comwrote in
news:l3********************************@4ax.com:
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
Jul 13 '08 #7

P: n/a
Ikke wrote:
"Peter Duniho" <Np*********@nnowslpianmk.comwrote in
news:op***************@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.Collections.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.dll';
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

Jul 13 '08 #8

P: n/a
On Sun, 13 Jul 2008 04:22:28 -0700, Ikke <ik**@hier.bewrote:
[...]
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
Jul 13 '08 #9

P: n/a
On Sun, 13 Jul 2008 07:41:32 -0700, Todd Carnes <to********@gmail.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
Jul 13 '08 #10

P: n/a
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

--
http://barrkel.blogspot.com/
Jul 13 '08 #11

P: n/a

"Ikke" <ik**@hier.bekirjoitti
viestissä:Xn************************@69.16.176.253 ...
Barry Kelly <ba***********@gmail.comwrote in
news:l3********************************@4ax.com:
<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>
Jul 13 '08 #12

P: n/a
Peter Duniho wrote:
On Sun, 13 Jul 2008 07:41:32 -0700, Todd Carnes <to********@gmail.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

Jul 13 '08 #13

This discussion thread is closed

Replies have been disabled for this discussion.