Accessing Properties of unknown object?

I need to create a new object of an unknown (at compiletime) object.  That's easy.  However, I then want to set any properties with the same names as the properties in my object.  How do you get a list of object properties at run time?  And how do you access them?
LVL 1
bcrotazAsked:
Who is Participating?
 
JimBob091197Connect With a Mentor Commented:
This be the answer then!  ;-)

Cheers,
JB
0
 
ZifNabCommented:
Yo Bcrotaz,

JimBob answered a 'sort a like' of question this day... He sended some source code for it. I received it too. But, I didn't wrote it, so JimBob should earn the points. I can send you his source code, but maybe it's better to wait for JB.

Regards, Zif.
0
 
JimBob091197Commented:
Hi bcrotaz & ZifNab

Zif, did u send the code to bcrotaz?  If not, and you (bcrotaz) want it, I will send it to you.  (Need your e-mail address.)

Cheers,
JB
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ZifNabCommented:
Hi JB, no I didn't send it to BCrotaz, because 1. I don't have BCrotaz's e-mail. 2. I was waiting for his email and would send it if it was urgent. 3. You should earn the points, not me. Regards, Zif.
0
 
bcrotazAuthor Commented:
bryan@concept-broadcast.co.uk

Thanks, JimBob.  This is what a Delphi 'Community' is all about!
0
 
JimBob091197Commented:
bcrotaz:  I have sent the unit to you.

Zif: Ta.  ;-)

Cheers,
JB
0
 
altenaCommented:
Could you guys close the problem? It seems to me the problem
is solved and the point are paid...

(And I dont get to write an article about type-libraries...)
0
 
JimBob091197Commented:
altena: Hold on a sec...  I'm just waiting for bcrotaz to evaluate the unit I sent him...
'course, if you want to write an article about type-libs, go ahead.  It's just not appropriate for this Q.

JB
0
 
altenaCommented:
JimBob: That means the question is "Locked" isnt it?

No type libraries? "not appropriate for this Q" really?
 In that case i would love to discuss the issue with you. Perhaps I can learn something here too...

If you want to, lets discuss this by e-mail. (the exchange
page will be a mess if we go on like this).

<AltenaR@Yahoo.com>
0
 
JimBob091197Commented:
Hi Altena

The reason I said type libs are not appropriate for this Q is that brotaz initially asked "I need to create a new object..." and from the context I figured "object" meant Delphi component, not OLE object.  Whether or not OLE objects can accomplish this via T-Libs is not the point.

If you have something to ask re type libs, ask it on Ex-Ex or mail me directly at davekw@iafrica.com.

If you may have something to teach me re type libs mail me too.

In the mean time, I'll wait for brotaz to indicate that he/she is happy with the unit I sent, or if it was totally irrelevant.

JB
0
 
bijoynCommented:
JimBoB

Hi Again, Would u send me the unit too ?. bijoy.nair@na.manpower.com.

Thanks in advance ( again ),

Bijoy
0
 
bcrotazAuthor Commented:
Well now.... I seem to have started a little war!
BTW I'm a 'He', JB.  I'm evaluating your unit tonight.
Looks like it's a bit popular.

I _am_ using Delphi objects, not components, but not OLE objects.  I thought that might introduce too much complexity to a simple problem....
0
 
JimBob091197Commented:
Hi bcrotaz the 'He'   ;-)

The unit I sent you will work on any object compiled in the {$M+} state.  TPersistent is compiled in this state, so anything inherited from TPersistent (i.e. TComponent, etc.) will work with the unit I sent you.

If you want your own object (derived from TObject, etc.) to work, you must enclose the definition of the object with {$M+} and {$M-}.

E.g.
type
{$M+}
  TMyObject = class
  private
    FSomething: string;
  published
    property Something: string read FSomething write FSomething;
  end;
{$M-}

The $M+ tells Delphi to include RTTI (Run-time Type Info) for that object.  BUT the RTTI gives info only for PUBLISHED properties!!

Regards,
JB
0
 
bcrotazAuthor Commented:
I knew about published properties being the only ones with RTTI.

Your unit...
i've looked through TypInfo (which I didn't know existed...!), and can't find anything about boolean properties.  Are they a special case of another type?
0
 
JimBob091197Commented:
Hi

Boolean properties are treated like Integers.  If you look at the unit I sent you, I implement GetBoolValue and SetBoolValue in a very similar way to GetIntValue and SetIntValue.

JB
0
 
bcrotazAuthor Commented:
u-huh. (with an Oxford English accent - of course!)
0
 
JimBob091197Commented:
Hi all,

Before this question disappears into complete oblivion, shall I answer it???  I am assuming that the unit did the trick.

JB
0
 
bcrotazAuthor Commented:
Yes please.
It was a good starting point.

Thanks
Bryan
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.