Solved

Accessing Properties of unknown object?

Posted on 1998-03-10
18
271 Views
Last Modified: 2013-11-23
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?
0
Comment
Question by:bcrotaz
  • 8
  • 5
  • 2
  • +2
18 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360373
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
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360374
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
 
LVL 8

Expert Comment

by:ZifNab
ID: 1360375
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
 
LVL 1

Author Comment

by:bcrotaz
ID: 1360376
bryan@concept-broadcast.co.uk

Thanks, JimBob.  This is what a Delphi 'Community' is all about!
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360377
bcrotaz:  I have sent the unit to you.

Zif: Ta.  ;-)

Cheers,
JB
0
 
LVL 3

Expert Comment

by:altena
ID: 1360378
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
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360379
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
 
LVL 3

Expert Comment

by:altena
ID: 1360380
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
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360381
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Expert Comment

by:bijoyn
ID: 1360382
JimBoB

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

Thanks in advance ( again ),

Bijoy
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1360383
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
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360384
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
 
LVL 1

Author Comment

by:bcrotaz
ID: 1360385
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
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360386
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
 
LVL 1

Author Comment

by:bcrotaz
ID: 1360387
u-huh. (with an Oxford English accent - of course!)
0
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1360388
Hi all,

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

JB
0
 
LVL 1

Author Comment

by:bcrotaz
ID: 1360389
Yes please.
It was a good starting point.

Thanks
Bryan
0
 
LVL 5

Accepted Solution

by:
JimBob091197 earned 200 total points
ID: 1360390
This be the answer then!  ;-)

Cheers,
JB
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

11 Experts available now in Live!

Get 1:1 Help Now