#1 2016-01-25 17:50:26

jaclas
Member
Registered: 2014-09-12
Posts: 215

Minor inconvenience :-)

Hi,

Unit mORMot.pas has a defined type PTypeInfo. It is incompatible with the Delphi native type PTypeInfo. For this reason I have often errors when compiling my own code where I use both mORMot.pas and TypInfo.pas units.

Is it possible to change the name of this type in mORMot, for example to PMTypeInfo?

kind regards

Last edited by jaclas (2016-01-25 17:50:54)

Offline

#2 2016-01-25 18:03:23

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 337

Re: Minor inconvenience :-)

Why not ust use SynCommons.PTypeInfo ? With some database constants you will have this problem too and other cases surely.


Esteban

Offline

#3 2016-01-25 18:11:26

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Minor inconvenience :-)

Both types would point to the same RTTI information, so you could use one instead of another easily.
And SynCommons.PTypeInfo has much more convenient methods than Delphi RTL's PTypeInfo.

Offline

#4 2016-01-25 18:40:06

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Minor inconvenience :-)

SynCommons.PTypeInfo is in implementation section of unit, private.

Last edited by jaclas (2016-01-25 18:40:52)

Offline

#5 2016-01-25 19:02:36

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Minor inconvenience :-)

This unfortunately does not solve the problem, because mORMot.pas does not have the PTypeData type (and additional functions like GetTypeData()), which forces me to use TypInfo - so the problem returns sad

Offline

#6 2016-01-25 19:21:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Minor inconvenience :-)

You have a better alternative to PTypeData with mORMot's TTypeInfo wrappers, using e.g. ClassType method for class properties, OrdType method for ordinal types, RecordType for record types, and so on...
Instead of a bulky PTypeData, you have dedicated types with some convenient wrapper methods.
Which method is missing for you?

Offline

#7 2016-01-25 22:17:53

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Minor inconvenience :-)

For example, how to replace this code?

g := GetTypeData(TypeInfo(IMyInterface)).Guid;

Offline

#8 2016-01-25 23:56:53

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Minor inconvenience :-)

Use http://synopse.info/files/html/api-1.18 … ERFACEGUID

Note that the IMyInterface is a TGuid....
So you can write g := IMyInterface

Offline

#9 2016-01-26 13:11:12

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Minor inconvenience :-)

Ok, that was a bad example,  I think about something like this:

var p : PTypeInfo;
...
g := GetTypeData(p).Guid;

But using mORMot RTTI creates a new problems. In other place of my code I use a System.Rtti.pas. Using it forces me to use native type PTypeInfo.
I must unfortunately abandon the use of incompatible PTypeInfo from mORMot and do some workaround sad

Last edited by jaclas (2016-01-26 13:12:30)

Offline

#10 2016-01-26 13:17:34

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Minor inconvenience :-)

If you define System.Rtti.pas AFTER mORMot.pas in your units "uses" clause, you would not have any problem.
PTypeInfo would refer to the one in Rtti.pas.

Offline

#11 2016-01-26 13:30:45

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Minor inconvenience :-)

PTypeInfo is defined in System.TypInfo.pas - and we return to the starting point :-)

Offline

#12 2016-01-26 13:40:38

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Minor inconvenience :-)

So, add System.TypInfo.pas AFTER mORMot.pas in your uses clause.
I do not see why it is difficult.

Type names collisions do often occur in Delphi.
You fix it either:
- By putting the expected order in your "uses" clause;
- Or by prefixing the type name (e.g. TypeInfo.PTypeInfo or mORMot.PTypeInfo).

Offline

#13 2016-01-26 15:19:41

jaclas
Member
Registered: 2014-09-12
Posts: 215

Re: Minor inconvenience :-)

I know, but these solutions are ... unsightly, dangerous, introduce depending on the source code order - this is not good.
I did alias on type PTypeInfo and I use that alias. Tough luck, let it be :-)

Offline

#14 2016-01-26 15:36:48

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,666
Website

Re: Minor inconvenience :-)

Since both types would point to the same RTTI information, there is no big issue at runtime to be encountered.
Everything should be identified at compile time, and therefore could be easily fixed by the proper order of units in the "uses" clause.

Offline

Board footer

Powered by FluxBB