473,372 Members | 1,157 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,372 software developers and data experts.

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
Jul 12 '08 #1
12 1264
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
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
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
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
"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
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
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
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
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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Jimmy Cerra | last post by:
I am a little confused how the memory for objects is allocated in JavaScript. David Flanagan, in "JavaScript: The Definitive Guide," states that each property of a class takes up memory space when...
2
by: Mark | last post by:
I have it in my head that I saw a marketing document from Microsoft with the total number of classes and methods in the .NET Framework. Something like 70,000 methods? I don't need precise numbers,...
3
by: Sam Sungshik Kong | last post by:
Hello! While using panel control, I wondered a thing. Panel class is subclass of Control class. Control class has KeyPress event and Focus() method, etc... Then Panel class must have them. I...
16
by: Art | last post by:
Hi, I'd like to be able to create a class that inherits "Label". I want to define a number of properties and methods for my new class. The Question: Can I prevent a user of this new class...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
3
by: rickeringill | last post by:
Hi comp.lang.javascript, I'm throwing this in for discussion. First up I don't claim to be any sort of authority on the ecmascript language spec - in fact I'm a relative newb to these more...
17
by: Bruce One | last post by:
Lets consider a class called Currency. This class must be the responsible for taking care of all calculations over currency exchanges, in such a way that I pass values in Euros and it returns the...
4
by: Gert Kok | last post by:
The microsoft page http://msdn2.microsoft.com/en-us/library/9fkccyh4.aspx states: Remarks (nr 4) Virtual properties behave like abstract methods, except for the differences in declaration...
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
3
by: tshad | last post by:
Is there a good primer on DataTables out there? Mainly I am looking for an article that lists the properties and methods (with examples) on the different properties you can use with a DataTable....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.