Solved

Getting properties with typinfo.pas

Posted on 1998-04-23
4
500 Views
Last Modified: 2013-11-23
I have an object, of unknown type.  I want a list of the published property names.  To get the number of items, I use:

nProps := GetTypeData(MyObject.ClassInfo)^.PropCount;

I get each property name with:

  GetPropInfos(Source.ClassInfo,SourceProps);
  for PropNo := 0 to nProps-1 do begin
    PropertyName:= (SourceProps[PropNo])^.Name;

This works for all properties except record types (eg TRect).  They're just not included in the list, or the count of properties....

Any ideas?


0
Comment
Question by:bcrotaz
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
extreme earned 100 total points
ID: 1336754
That's because propinfo works only with the published properties of objects. And with properties that *can* be published, records, the same as other types, don't works with typeinfo. Try to put a record published, then register the component with Delphi and look in the object inspector. Doesn't works. If you need something that has fields you have to use a class, like TFont for example. If you need this for a record like TRect, build a class with the same fields of TRect and if you want you can add it some methods to give it more functionality.
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1336755
OK. That's disappointing.  I'll have to find a workaround.
I originally used a class - it's for a date-time type thing.
The class had the DateToStr etc methods.
I found I got access violations all over the place.
I'll look at how TFont is used.
0
 
LVL 1

Expert Comment

by:extreme
ID: 1336756
You can't use TDateTime for that? TDateTime is a floating point value, that is perfectly compatible with published properties and RTTI. Of course if you want to split it in fields you have to use a class.
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1336757
No - I need frames too.
I did it with a Longint.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now