Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2009-10

TObject differences between fpc and delphi

21 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Paul Ishenin

Hello, FPC developers' list

I have compared what d2010 TObject has and found a few differences:

1. Dispatch method is virtual
2. new method: class function UnitName: string;
3. new method: function Equals(Obj: TObject): Boolean; virtual;
4. new method: function GetHashCode: Integer; virtual;
5. new method: function ToString: string; virtual;

Documentation:
http://docwiki.embarcadero.com/VCL/en/System.TObject.Dispatch http://docwiki.embarcadero.com/VCL/en/System.TObject.UnitName http://docwiki.embarcadero.com/VCL/en/System.TObject.Equals http://docwiki.embarcadero.com/VCL/en/System.TObject.GetHashCode http://docwiki.embarcadero.com/VCL/en/System.TObject.ToString

Which of that changes are welcome for FPC?

Best regards,
Paul Ishenin.

Reply by email

Florian Klaempfl
to Paul Ishenin
Show quoted text 16 lines
I have compared what d2010 TObject has and found a few differences: 1. Dispatch method is virtual 2. new method: class function UnitName: string; 3. new method: function Equals(Obj: TObject): Boolean; virtual; 4. new method: function GetHashCode: Integer; virtual; 5. new method: function ToString: string; virtual; Documentation: http://docwiki.embarcadero.com/VCL/en/System.TObject.Dispatch http://docwiki.embarcadero.com/VCL/en/System.TObject.UnitName http://docwiki.embarcadero.com/VCL/en/System.TObject.Equals http://docwiki.embarcadero.com/VCL/en/System.TObject.GetHashCode http://docwiki.embarcadero.com/VCL/en/System.TObject.ToString Which of that changes are welcome for FPC?

Since we opened the d2010 can of worms anyways, I think all would be accepted.

Reply by email

Michael Van Canneyt
to Florian Klaempfl
Florian Klaempfl wrote 20 lines
Paul Ishenin schrieb: > I have compared what d2010 TObject has and found a few differences: > > 1. Dispatch method is virtual > 2. new method: class function UnitName: string; > 3. new method: function Equals(Obj: TObject): Boolean; virtual; > 4. new method: function GetHashCode: Integer; virtual; > 5. new method: function ToString: string; virtual; > > Documentation: > http://docwiki.embarcadero.com/VCL/en/System.TObject.Dispatch > http://docwiki.embarcadero.com/VCL/en/System.TObject.UnitName > http://docwiki.embarcadero.com/VCL/en/System.TObject.Equals > http://docwiki.embarcadero.com/VCL/en/System.TObject.GetHashCode > http://docwiki.embarcadero.com/VCL/en/System.TObject.ToString > > Which of that changes are welcome for FPC? Since we opened the d2010 can of worms anyways, I think all would be accepted.

I was going to say the same :-)

Although I think that TObject.ToString will give a lot of problems for things like tiOPF...

On the other hand, UnitName may come in handy for the Lazarus IDE.

Michael.

Reply by email

Paul Ishenin
to Michael Van Canneyt
Michael Van Canneyt wrote
I was going to say the same :-) Although I think that TObject.ToString will give a lot of problems for things like tiOPF...

actually it adds problems even to the fpc rtl :) since it has toString member in the component stream parser.

Best regards,
Paul Ishenin.

Reply by email

Thaddy
to Florian Klaempfl: Since we opened the d2010 can of worms anyways, I think all would be accepted.
Florian Klaempfl wrote 23 lines
Paul Ishenin schrieb: > I have compared what d2010 TObject has and found a few differences: > > 1. Dispatch method is virtual > 2. new method: class function UnitName: string; > 3. new method: function Equals(Obj: TObject): Boolean; virtual; > 4. new method: function GetHashCode: Integer; virtual; > 5. new method: function ToString: string; virtual; > > Documentation: > http://docwiki.embarcadero.com/VCL/en/System.TObject.Dispatch > http://docwiki.embarcadero.com/VCL/en/System.TObject.UnitName > http://docwiki.embarcadero.com/VCL/en/System.TObject.Equals > http://docwiki.embarcadero.com/VCL/en/System.TObject.GetHashCode > http://docwiki.embarcadero.com/VCL/en/System.TObject.ToString > > Which of that changes are welcome for FPC? > Since we opened the d2010 can of worms anyways, I think all would be accepted.

Yes, but..
Canned food can contain preservatives that are not always healthy. The ToString Javaism is poorly implemented in Delphi. I suggest that objfpc mode should be based on json or similar standards, which are already available. Not just rtti writeouts.

Reply by email

Paul Ishenin
to Thaddy
Thaddy wrote
The ToString Javaism is poorly implemented in Delphi. I suggest that objfpc mode should be based on json or similar standards, which are already available. Not just rtti writeouts.

TObject can't be one for ObjFpc mode and one for delphi mode.

Best regards,
Paul Ishenin.

Reply by email

Mattias Gärtner
to Michael Van Canneyt: I was going to say the same :-) Although I think that TObject.ToString will give a lot…

Zitat von Michael Van Canneyt :

Show quoted text 31 lines
On Tue, 27 Oct 2009, Florian Klaempfl wrote: > Paul Ishenin schrieb: >> I have compared what d2010 TObject has and found a few differences: >> >> 1. Dispatch method is virtual >> 2. new method: class function UnitName: string; >> 3. new method: function Equals(Obj: TObject): Boolean; virtual; >> 4. new method: function GetHashCode: Integer; virtual; >> 5. new method: function ToString: string; virtual; >> >> Documentation: >> http://docwiki.embarcadero.com/VCL/en/System.TObject.Dispatch >> http://docwiki.embarcadero.com/VCL/en/System.TObject.UnitName >> http://docwiki.embarcadero.com/VCL/en/System.TObject.Equals >> http://docwiki.embarcadero.com/VCL/en/System.TObject.GetHashCode >> http://docwiki.embarcadero.com/VCL/en/System.TObject.ToString >> >> Which of that changes are welcome for FPC? > > Since we opened the d2010 can of worms anyways, I think all would be > accepted. I was going to say the same :-) Although I think that TObject.ToString will give a lot of problems for things like tiOPF... On the other hand, UnitName may come in handy for the Lazarus IDE.

Lazarus already reads the unitname from the RTTI (see propedits.pp) and I guess MSEgui uses that too.
There are no classes yet without RTTI in lazarus where the unit name is needed.

Maybe it can be useful for debugging?

Mattias

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt: I was going to say the same :-) Although I think that TObject.ToString will give a lot…

2009/10/27 Michael Van Canneyt :

Show quoted text 5 lines
I was going to say the same :-) Although I think that  TObject.ToString will give a lot of problems for things like tiOPF...

I was going to say the same. ;-) I just clicked on the link Paul posted to see what ToString does and compare it to tiOPF.

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Graeme Geldenhuys
to Thaddy: Yes, but.. Canned food can contain preservatives that are not always healthy. The…

2009/10/27 Thaddy :

The ToString Javaism is poorly implemented in Delphi. I suggest that objfpc mode should be based on json or similar standards, which are already available. Not just rtti writeouts.

Based on the documentation available at Embarcadero, TObject.ToString is very simple - it just returns the ClassName by default.

------------------------------------
For example, calling System.TObject.ToString on a TButton instance returns a string containing "TButton".
-------------------------------------

Obviously the developer can override it and return more details, but by default it's the same as 'ClassName' property

Regards, - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Paul Ishenin
to Michael Van Canneyt: I was going to say the same :-) Although I think that TObject.ToString will give a lot…
Michael Van Canneyt wrote
On the other hand, UnitName may come in handy for the Lazarus IDE.

And this is the most difficult thing amoung other new methods :)

I am trying to get UnitName from the RTTI but have some problems:

1. If I call PTypeInfo(TypeInfo(TObject))^.Kind then I get tkClass and UnitInfo can be retrieved since tkClass has this member.

2. If I am using PTypeInfo(TypeInfo(Self))^.Kind inside a class method I get tkUnknown and UnitName is not avaiable ofcource.

3. If I am using ClassInfo iside a class method then it returns nil if the class has no RTTI.

Few questions now:
a) Why TypeInfo(TObject) TObject.ClassInfo?
b) Why TypeInfo(TPersistent) = TPersistent.ClassInfo? c) How to get TypeInfo of the class inside that class class method?

After all, if it should not use RTTI then I need to change the compiler to store also UnitName near the ClassName field but this is a be bad change since vmtMethodStart will change it offset and according to RTL comments few methods depends on that offsetts.

So what is the best way to implement this UnitName method?

Best regards,
Paul Ishenin.

Reply by email

Michael Van Canneyt
to Paul Ishenin
Paul Ishenin wrote 16 lines
Michael Van Canneyt wrote: > On the other hand, UnitName may come in handy for the Lazarus IDE. And this is the most difficult thing amoung other new methods :) I am trying to get UnitName from the RTTI but have some problems: 1. If I call PTypeInfo(TypeInfo(TObject))^.Kind then I get tkClass and UnitInfo can be retrieved since tkClass has this member. 2. If I am using PTypeInfo(TypeInfo(Self))^.Kind inside a class method I get tkUnknown and UnitName is not avaiable ofcource. 3. If I am using ClassInfo iside a class method then it returns nil if the class has no RTTI.

This last is correct, since the ClassInfo is part of the RTTI ?

Few questions now: a) Why TypeInfo(TObject) TObject.ClassInfo? b) Why TypeInfo(TPersistent) = TPersistent.ClassInfo?

Because TPersistent is compiled in $M+ ?

c) How to get TypeInfo of the class inside that class class method?

I think that Florian should answer this, but it seems like a bug to me ?

Michael.

Reply by email

Paul Ishenin
to Michael Van Canneyt
Michael Van Canneyt wrote 5 lines
> Few questions now: > a) Why TypeInfo(TObject) TObject.ClassInfo? > b) Why TypeInfo(TPersistent) = TPersistent.ClassInfo? Because TPersistent is compiled in $M+ ?

Yes, that's why I gived that TPersistent example here. I can't figure our how TypeInfo(TObject) works if TObject has no RTTI and since it works then why TObject.ClassInfo = nil.

Best regards,
Paul Ishenin.

Reply by email

Paul Ishenin
to Paul Ishenin: And this is the most difficult thing amoung other new methods :) I am trying to get…
Paul Ishenin wrote 5 lines
I am trying to get UnitName from the RTTI but have some problems: ... Few questions now: a) Why TypeInfo(TObject) TObject.ClassInfo? b) Why TypeInfo(TPersistent) = TPersistent.ClassInfo?

No idea why but it is the same in delphi < d2010. Probably in d2010 it depends on project rtti settings. And UnitName = '' in d2009 for classes with no RTTI.

c) How to get TypeInfo of the class inside that class class method?

Probably no way except the using the same info which ClassType using.

So what is the best way to implement this UnitName method?

Still the question. Using RTTI and return empty result if it does not exists or changing the compiler to write unit name near the class name?

Best regards,
Paul Ishenin.

Reply by email

Michael Van Canneyt
to Paul Ishenin
Paul Ishenin wrote 9 lines
Paul Ishenin wrote: > I am trying to get UnitName from the RTTI but have some problems: > ... > Few questions now: > a) Why TypeInfo(TObject) TObject.ClassInfo? > b) Why TypeInfo(TPersistent) = TPersistent.ClassInfo? No idea why but it is the same in delphi < d2010. Probably in d2010 it depends on project rtti settings. And UnitName = '' in d2009 for classes with no RTTI.

The implementation is probably the same: consult RTTI if present. If it is not present, then return empty...

Show quoted text 6 lines
> c) How to get TypeInfo of the class inside that class class method? Probably no way except the using the same info which ClassType using. > So what is the best way to implement this UnitName method? Still the question. Using RTTI and return empty result if it does not exists or changing the compiler to write unit name near the class name?

Maybe generate partial RTTI for classes not in $M+ ?

Michaek

Reply by email

Paul Ishenin
to Michael Van Canneyt
Michael Van Canneyt wrote
Maybe generate partial RTTI for classes not in $M+ ?

I think it is already generated since TypeInfo(TObject) returns data but probably not written by the compiler to the vmtTypeInfo offset.

Best regards,
Paul Ishenin.

Reply by email