Solved

Accessing Properties of unknown object?

Posted on 1998-03-10
18
274 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 141
Create Database on Android via Delphi dbExpress 3 110
LAN or WAN ? 11 95
Delphi Yen format 3 45
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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