Jump to content
Attila Kovacs

RTTI in dpr / console app dpr

Recommended Posts

Is that anywhere documented that RTTI is screwd up/missing on types declared in a console app's dpr? Maybe every kind of dpr.

brr

Share this post


Link to post

Wasn't said explicitly ... but RTTI is available for public declaration. dpr project (program/library/console,...) are implementation (they don't have interface) those they are not public.

  • Like 1

Share this post


Link to post
16 minutes ago, Mahdi Safsafi said:

Wasn't said explicitly ... but RTTI is available for public declaration. dpr project (program/library/console,...) are implementation (they don't have interface) those they are not public.

RTTI is available for all types, be they public (interface section), or private (implementation section or project file). 

Share this post


Link to post
5 minutes ago, David Heffernan said:

RTTI is available for all types, be they public (interface section), or private (implementation section or project file). 

I know that, I was meaning RttiContext.GetTypes 

  • Thanks 1

Share this post


Link to post

The question is answered as far as I can see, Ctx.FindType(TypeName) fails on types declared in the dpr, doesn't matter what directives I put there,

@Mahdi Safsafi's answer is very plausible for me, with not having interface section, no public pool for them.

 

Not a big deal, just the usual lazy prototyping in a console dpr...

 

thx

  • Like 1

Share this post


Link to post
On 6/11/2020 at 9:43 PM, Mahdi Safsafi said:

Wasn't said explicitly ... but RTTI is available for public declaration. dpr project (program/library/console,...) are implementation (they don't have interface) those they are not public.

program Project1;

{$APPTYPE CONSOLE}

uses
  System.SysUtils, System.Rtti;

type
  TMyClass = class
  public
    procedure Foo;
  end;

procedure TMyClass.Foo;
begin
end;

procedure Main;
var
  ctx: TRttiContext;
  Method: TRttiMethod;
begin
  Method := ctx.GetType(TMyClass).GetMethod('Foo');
  Writeln(Method.Name);
  Writeln(Format('%p', [Method.CodeAddress]));
end;

begin
  try
    Main;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.

This demonstrates that what you said is not correct.

Share this post


Link to post
On 6/11/2020 at 11:39 PM, Attila Kovacs said:

The question is answered as far as I can see, Ctx.FindType(TypeName) fails on types declared in the dpr, doesn't matter what directives I put there,

@Mahdi Safsafi's answer is very plausible for me, with not having interface section, no public pool for them.

My post above demonstrates that RTTI does exist. I think that the real issue is that these types don't have qualified names.

Share this post


Link to post

There is a qualified name, the RTTI lib looks for <projectname.Type> in case of "FindType", however TRealPackage.MakeTypeLookupTable / GetUnits returning only units, not the dpr itself (it's just not in the the PPackageTypeInfo).


So yes, there is RTTI but no TypeInfo.

 

Maybe because (as you mention) the <projectname.type> is not a valid qualified name or just forgotten or because it's in the implementation section and does not belong to the PackageTypeInfo anyway (which I think is the reason).

 

But to get a resolution to this, strictly answering my question you are right.

And the answer to my problem was what Mahdi said.

 

I could not ask better without knowing a lot of implementation detail.

 

Thank you all.

Share this post


Link to post

@David Heffernan First, do you really think that I'm missing a basic fact about RTTI ? FYI, my component TzObjectInspector is entirely build with RTTI ! 

Second, I really don't know what's the purpose of your example since I answered you "I know that, I was meaning RttiContext.GetTypes". I thought that would be enough to put you on the road. I'm still thinking that you're not understanding neither Attila question nor my answer.

Third, I answered with the context of the question, from the first sight, I knew that Attila was meaning inquiring RTTI declared on a program (not a unit).

Last thing, If that going to make you happy, I'll rearrange my sentence :

Wasn't said explicitly ... but inquiring RTTI is available for public declaration. dpr project (program/library/console,...) are implementation (they don't have interface) those they are not public.

Share this post


Link to post

Mahdi - calm down. Now.

This will clearly not be the next thread where you can celebrate in public your discrepancies with David. His example is absolutely valid to demonstrate that RTTI is actually working in plan .dpr files.

  • Like 1

Share this post


Link to post
7 minutes ago, Daniel said:

Mahdi - calm down. Now.

This will clearly not be the next thread where you can celebrate in public your discrepancies with David. His example is absolutely valid to demonstrate that RTTI is actually working in plan .dpr files.

@Daniel You're not understanding whats happening here and yet you took David side !

Read carefully my answer, I didn't say at all David example/answer is wrong ! all what I said, David misunderstood my answer ... nothing more !
Rather than taking your friend side, It would be better to understand first what's going on ... ok ?

  • Like 2

Share this post


Link to post

Ignoring Mahdis corrected answer

On 6/11/2020 at 11:08 PM, Mahdi Safsafi said:

I know that, I was meaning RttiContext.GetTypes

(which was actually the answer, he nailed it, even though my question was very lazy and broad)

 

and acting like a spring, chanting the same in reply to his first comment is nothing else just trolling and does not help here.

  • Like 1
  • Thanks 1

Share this post


Link to post
6 minutes ago, Attila Kovacs said:

Ignoring Mahdis corrected answer

(which was actually the answer, he nailed it, even though my question was very lazy and broad)

  

and acting like a spring, chanting the same in reply to his first comment is nothing else just trolling and does not help here.

Too bad @Daniel didn't saw that 😥

 

Share this post


Link to post
1 hour ago, Mahdi Safsafi said:

First, do you really think that I'm missing a basic fact about RTTI ?

I don't think about you at all. I was interested in the question. Try to view comments as impersonal. 

 

1 hour ago, Mahdi Safsafi said:

I'm still thinking that you're not understanding neither Attila question nor my answer.

That's entirely possible. I'm interested in learning. It's possible that my misunderstanding is because of imprecise statements. It's possible I'm slow on the uptake.

 

To be clear, I thought you said that types declared in the project file had no RTTI. I checked that and was able to retrieve RTTI for such types.

 

I simply don't understand the strength of your reaction. 

  • Like 1

Share this post


Link to post
Quote

I don't think about you at all. I was interested in the question. Try to view comments as impersonal. 

You're absolutely right ... I just wish if your friend Daniel did too !  

Quote

To be clear, I thought you said that types declared in the project file had no RTTI. I checked that and was able to retrieve RTTI for such types.

Now, we're clearly understanding each other.

 

Quote

I simply don't understand the strength of your reaction. 

I got the feeling that you were trolling. You would clearly understand if role changed and you were at my place.

I'm very sorry if this at any case hurts you.

 

  • Like 1

Share this post


Link to post
1 hour ago, Attila Kovacs said:

found by accident

 

 

So, is it the case that rtti is generated for types declared in the project file, but these rtti types don't have a qualified name? 

Share this post


Link to post
Posted (edited)

http://docwiki.embarcadero.com/Libraries/Rio/en/System.Rtti.TRttiType.QualifiedName

"QualifiedName is only available for public types declared in the interface section of a unit."

 

image.thumb.png.a9cd3e326c757514877f56443bfb7f20.png

 

FQN makes only sense for public declarations = interface section, so no FQN for dpr members, and no lookup-table entry for those non-public types.

TRealPackage.MakeTypeLookupTable makes it clear as it starts with "units := GetUnits;".

 

At the end, we are still discussing the same what was said to me 3 days ago.

 

Edited by Attila Kovacs

Share this post


Link to post
Quote

So, is it the case that rtti is generated for types declared in the project file, but these rtti types don't have a qualified name? 

 

I did a little experimentation to explore how compiler deals with rtti/qualified_name, let me know if you're interested.

 

  • Like 1

Share this post


Link to post
5 hours ago, Mahdi Safsafi said:

I did a little experimentation to explore how compiler deals with rtti/qualified_name, let me know if you're interested.

We have this folk saying "good deeds do not need request", if you already wasted your time thinking about that and made an interesting experiment, please share it will be good, i am very interested.

 

And thank you.

Share this post


Link to post
4 hours ago, Kas Ob. said:

We have this folk saying "good deeds do not need request", if you already wasted your time thinking about that and made an interesting experiment, please share it will be good, i am very interested.

 

And thank you.

Thank you 😊 

In the attached file, you'll find what I did and an interpretation to results (of course from my point of view). Let me know if you've any questions.

program.dpr

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×