Thread View: borland.public.delphi.rtl.dotnet
15 messages
15 total messages
Started by Bengt Skogvall
Wed, 13 Apr 2005 17:19
Accessing nested classes in Delphi.NET
Author: Bengt Skogvall
Date: Wed, 13 Apr 2005 17:19
Date: Wed, 13 Apr 2005 17:19
25 lines
1297 bytes
1297 bytes
I have a C# assembly like this:
public class Class
{
public Class()
{
}
public class nest
{
public string x = "hallo";
}
}
If I try to get the literal x from Delphi I write
n:=&Class.create;
s:=n.nest.x;
hower I get a compiler error saying that x is not a variable or function.
How can I access x?
Regards,
Bengt
Re: Accessing nested classes in Delphi.NET
Author: Craig Stuntz TeamB
Date: Wed, 13 Apr 2005 18:38
Date: Wed, 13 Apr 2005 18:38
15 lines
1619 bytes
1619 bytes
Bengt Skogvall wrote: > hower I get a compiler error saying that x is not a variable or > function. > > How can I access x? You're trying to use nest as an instance property of Class, and it isn't (or, at least, if it is you didn't post that portion of the code). That code won't work in C#, either. What do you actually want to do? -- Craig Stuntz [TeamB] � Vertex Systems Corp. � Columbus, OH Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
Re: Accessing nested classes in Delphi.NET
Author: Bengt Skogvall
Date: Wed, 13 Apr 2005 19:23
Date: Wed, 13 Apr 2005 19:23
36 lines
1841 bytes
1841 bytes
there was a small error in the code: should be public const string x = "hallo"; The code was not written by me, but I have to use it :-( The idea is to supply constant strings. The way it should be called is s := &Class.nest.x; but that does not work with Delphi.NET either. in C#, the Class compiles ok and I can get the value of x by calling s = Class.nest.x; -Bengt Craig Stuntz [TeamB] wrote: > Bengt Skogvall wrote: > > >>hower I get a compiler error saying that x is not a variable or >>function. >> >>How can I access x? > > > You're trying to use nest as an instance property of Class, and it > isn't (or, at least, if it is you didn't post that portion of the > code). That code won't work in C#, either. What do you actually want to > do? >
Re: Accessing nested classes in Delphi.NET
Author: Biot!
Date: Wed, 13 Apr 2005 20:47
Date: Wed, 13 Apr 2005 20:47
32 lines
1545 bytes
1545 bytes
"Bengt Skogvall" <bengt@skogvall.de> wrote in message
news:425d54c8@newsgroups.borland.com...
> I have a C# assembly like this:
>
> public class Class
> {
> public Class()
> {
> }
> public class nest
> {
> public string x = "hallo";
> }
> }
>
>
> If I try to get the literal x from Delphi I write
>
> n:=&Class.create;
> s:=n.nest.x;
>
> hower I get a compiler error saying that x is not a variable or function.
>
> How can I access x?
>
> Regards,
> Bengt
try this:
n := &Class.nest.Create;
s := n.x;
Re: Accessing nested classes in Delphi.NET
Author: Bengt Skogvall
Date: Thu, 14 Apr 2005 10:05
Date: Thu, 14 Apr 2005 10:05
10 lines
1177 bytes
1177 bytes
> try this: > > n := &Class.nest.Create; > s := n.x; > > Well, it compiles, but then you get a run time error saying "Field not found: nest.x.."
Re: Accessing nested classes in Delphi.NET
Author: Craig Stuntz TeamB
Date: Thu, 14 Apr 2005 14:11
Date: Thu, 14 Apr 2005 14:11
13 lines
1723 bytes
1723 bytes
Bengt Skogvall wrote: > Well, it compiles, but then you get a run time error saying "Field > not found: nest.x.." Are you posting the actual code you are using here? Because that just doesn't make sense. -- Craig Stuntz [TeamB] � Vertex Systems Corp. � Columbus, OH Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz Everything You Need to Know About InterBase Character Sets: http://blogs.teamb.com/craigstuntz/articles/403.aspx
Re: Accessing nested classes in Delphi.NET
Author: Bengt Skogvall
Date: Fri, 15 Apr 2005 07:09
Date: Fri, 15 Apr 2005 07:09
38 lines
1904 bytes
1904 bytes
> Are you posting the actual code you are using here? Because that just
> doesn't make sense.
>
OK, here is the code I have:
public abstract class _INSTRUMENT : FirebirdSqlEntity
{
// skipped the constructor and other methods
public class ColumnNames
{
public const string INSTRUMENTNR = "INSTRUMENTNR";
public const string BESCHREIBUNG = "BESCHREIBUNG";
}
}
which is turned into a real class by
public class INSTRUMENT : _INSTRUMENT
{
public INSTRUMENT()
{
}
}
And I want to get to the strings. In C# I can do
s = INSTRUMENT.ColumnNames.BESCHREIBUNG;
In Delphi, it shoud work IMO:
s:=INSTRUMENT.ColumnNames.BESCHREIBUNG;
but it does not. :-(
-B
Re: Accessing nested classes in Delphi.NET
Author: Biot!
Date: Fri, 15 Apr 2005 18:29
Date: Fri, 15 Apr 2005 18:29
43 lines
2042 bytes
2042 bytes
"Bengt Skogvall" <bengt@skogvall.de> wrote in message
news:425f6894$1@newsgroups.borland.com...
> > Are you posting the actual code you are using here? Because that just
> > doesn't make sense.
> >
>
> OK, here is the code I have:
>
> public abstract class _INSTRUMENT : FirebirdSqlEntity
> {
> // skipped the constructor and other methods
>
> public class ColumnNames
> {
> public const string INSTRUMENTNR = "INSTRUMENTNR";
> public const string BESCHREIBUNG = "BESCHREIBUNG";
> }
> }
>
> which is turned into a real class by
>
> public class INSTRUMENT : _INSTRUMENT
> {
> public INSTRUMENT()
> {
>
> }
> }
>
> And I want to get to the strings. In C# I can do
>
> s = INSTRUMENT.ColumnNames.BESCHREIBUNG;
>
> In Delphi, it shoud work IMO:
>
> s:=INSTRUMENT.ColumnNames.BESCHREIBUNG;
>
> but it does not. :-(
>
> -B
I think there is something wrong with your definition in Delphi. How do you
define the interface part of class in Delphi?
Re: Accessing nested classes in Delphi.NET
Author: Bengt Skogvall
Date: Fri, 15 Apr 2005 23:00
Date: Fri, 15 Apr 2005 23:00
10 lines
1391 bytes
1391 bytes
> > I think there is something wrong with your definition in Delphi. How do you > define the interface part of class in Delphi? > > I am not sure I understand what you mean? I simply add a reference to the assembly where the c# class is. The rest (= Interface) is done automagically by Delphi. -Bengt
Re: Accessing nested classes in Delphi.NET
Author: Biot!
Date: Sat, 16 Apr 2005 14:18
Date: Sat, 16 Apr 2005 14:18
17 lines
1727 bytes
1727 bytes
"Bengt Skogvall" <bengt@skogvall.de> wrote in message news:426047a1@newsgroups.borland.com... > > > > I think there is something wrong with your definition in Delphi. How do you > > define the interface part of class in Delphi? > > > > > I am not sure I understand what you mean? I simply add a reference to > the assembly where the c# class is. The rest (= Interface) is done > automagically by Delphi. > Sorry, I thought you are going to translate it to delphi. What is the error code when you compile & maybe run this: s:=INSTRUMENT.ColumnNames.BESCHREIBUNG
Re: Accessing nested classes in Delphi.NET
Author: Bengt Skogvall
Date: Mon, 18 Apr 2005 07:10
Date: Mon, 18 Apr 2005 07:10
12 lines
1562 bytes
1562 bytes
> Sorry, I thought you are going to translate it to delphi. No Problem :-) > > What is the error code when you compile & maybe run this: > s:=INSTRUMENT.ColumnNames.BESCHREIBUNG > Translated form German: "Unknown indentifier" (marking BESCHREIBUNG) already at Compile time :-(
Re: Accessing nested classes in Delphi.NET
Author: Craig Stuntz TeamB
Date: Mon, 18 Apr 2005 13:01
Date: Mon, 18 Apr 2005 13:01
63 lines
2726 bytes
2726 bytes
Bengt Skogvall wrote:
> And I want to get to the strings. In C# I can do
>
> s = INSTRUMENT.ColumnNames.BESCHREIBUNG;
OK, that makes *a lot* more sense. Your original Delphi code was quite
misleading because you were using an *instance* of what is, in this
example, INSTRUMENT rather than the class itself as you do above.
> In Delphi, it shoud work IMO:
>
> s:=INSTRUMENT.ColumnNames.BESCHREIBUNG;
And indeed, this works just fine for me. Code Completion doesn't find
it, but the project compiles and runs.
Sample projects included below:
using System;
namespace CSharpLib
{
public abstract class _INSTRUMENT : System.Object
{
public class ColumnNames
{
public const string INSTRUMENTNR = "INSTRUMENTNR";
public const string BESCHREIBUNG = "BESCHREIBUNG";
}
}
public class INSTRUMENT : _INSTRUMENT
{
public INSTRUMENT(): base(){}
}
}
program Project4;
{$APPTYPE CONSOLE}
{%DelphiDotNetAssemblyCompiler 'CSharpLib\bin\Debug\CSharpLib.dll'}
uses
SysUtils, CSharpLib;
var
S: String;
begin
S := INSTRUMENT.ColumnNames.INSTRUMENTNR;
WriteLn(S);
S := INSTRUMENT.ColumnNames.BESCHREIBUNG;
WriteLn(S);
ReadLn;
end.
--
Craig Stuntz [TeamB] � Vertex Systems Corp. � Columbus, OH
Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz
Please read and follow Borland's rules for the user of their
news server: http://info.borland.com/newsgroups/guide.html
Re: Accessing nested classes in Delphi.NET
Author: Bengt Skogvall
Date: Tue, 19 Apr 2005 08:33
Date: Tue, 19 Apr 2005 08:33
82 lines
3104 bytes
3104 bytes
Indeed, it works. Thanks a lot! :-)
I have learnt a lot about c# and Delphi.NET and how they interoperate.
My mistake was really that I thought I should be able to access the
string values using the instaciated class instead of the class itself.
However, there is still one thing that is not clear to me: The strings
get truncated.
Look at the output:
INSTRU
BESCHR
How can I get the rest of the strings?
-Bengt
Craig Stuntz [TeamB] wrote:
> Bengt Skogvall wrote:
>
>
>>And I want to get to the strings. In C# I can do
>>
>> s = INSTRUMENT.ColumnNames.BESCHREIBUNG;
>
>
> OK, that makes *a lot* more sense. Your original Delphi code was quite
> misleading because you were using an *instance* of what is, in this
> example, INSTRUMENT rather than the class itself as you do above.
>
>
>>In Delphi, it shoud work IMO:
>>
>> s:=INSTRUMENT.ColumnNames.BESCHREIBUNG;
>
>
> And indeed, this works just fine for me. Code Completion doesn't find
> it, but the project compiles and runs.
>
> Sample projects included below:
>
> using System;
>
> namespace CSharpLib
> {
> public abstract class _INSTRUMENT : System.Object
> {
> public class ColumnNames
> {
> public const string INSTRUMENTNR = "INSTRUMENTNR";
> public const string BESCHREIBUNG = "BESCHREIBUNG";
> }
> }
>
> public class INSTRUMENT : _INSTRUMENT
> {
> public INSTRUMENT(): base(){}
> }
> }
>
> program Project4;
>
> {$APPTYPE CONSOLE}
>
> {%DelphiDotNetAssemblyCompiler 'CSharpLib\bin\Debug\CSharpLib.dll'}
>
> uses
> SysUtils, CSharpLib;
>
> var
> S: String;
>
> begin
> S := INSTRUMENT.ColumnNames.INSTRUMENTNR;
> WriteLn(S);
> S := INSTRUMENT.ColumnNames.BESCHREIBUNG;
> WriteLn(S);
> ReadLn;
> end.
>
Re: Accessing nested classes in Delphi.NET
Author: Bengt Skogvall
Date: Tue, 19 Apr 2005 08:53
Date: Tue, 19 Apr 2005 08:53
9 lines
1358 bytes
1358 bytes
> Look at the output: > > INSTRU > BESCHR > > How can I get the rest of the strings? > Actually, it turns out I get only half the length of any given string!
Re: Accessing nested classes in Delphi.NET
Author: Craig Stuntz TeamB
Date: Tue, 19 Apr 2005 13:30
Date: Tue, 19 Apr 2005 13:30
31 lines
2332 bytes
2332 bytes
Bengt Skogvall wrote: > I have learnt a lot about c# and Delphi.NET and how they > interoperate. My mistake was really that I thought I should be able > to access the string values using the instaciated class instead of > the class itself. Delphi for .NET and C# work identically in this respect; there is a clear separation between types and instances. > However, there is still one thing that is not clear to me: The > strings get truncated. > > Look at the output: > > INSTRU > BESCHR I'm seeing that, too. I'm not sure what is causing it. When I browse the compiled C# assembly in Reflector I see the full string, so the problem is on the Delphi end. > > How can I get the rest of the strings? -- Craig Stuntz [TeamB] � Vertex Systems Corp. � Columbus, OH Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz Please read and follow Borland's rules for the user of their news server: http://info.borland.com/newsgroups/guide.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads