comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » how to get info on object fields
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: how to get info on object fields [message #9881 is a reply to message #9782] Mon, 25 August 1997 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
Mirko Vukovic writes:

> I was trying to write a general extraction routine for objects. The
> idea was to pass the name of a field, it would check if the field
> exists, get its tag number and extract it. It would work on the object
> as if it were a structure. But TAG_NAMES does not work on objects
> (which does make sense as SELF is still an object (type =11), not a
> structure). (see code below for my implementation).
>
> I like using objects, but sometimes they are too cumbersome for
> debugging purposes. I would also like to have a set of general routines
> applicable to all objects (via inheritance). That is why a general
> routine for extracting a field would be nice. Any clues how I might go
> about it?

I used this code to get something working in just a few minutes.
These objects can have superclasses, of course, and I am not
checking for that. You could use Obj_Class to find all the
superclass structures in an iterative way. The code would not
be too hard to implement.

The way this code works is to use Obj_Class to get the
name of the object, which is the name of the structure
you want. I create the right kind of structure with
the Execute command. To extract the field, I have to
use a second Execute statement.

FUNCTION OBJECT::EXTRACT, field

; Check if FIELD is a valid field name. If it is,
; return the field. If not, return -1.

thisClass = Obj_Class(self)
ok = Execute('thisStruct = {' + thisClass + '}')
structFields = Tag_Names(thisStruct)
index = WHERE(structFields EQ StrUpCase(field), count)
IF count EQ 1 THEN BEGIN
ok = Execute('Return, SELF.' + structFields(index(0)))
ENDIF ELSE BEGIN
Message, 'Can not find field "' + field + $
'" in structure.', /Informational
RETURN, -1
ENDELSE
END

This should give you some ideas.

Cheers,

David

-----------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
Customizable IDL Programming Courses
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com
[Message index]
 
Read Message
Read Message
Read Message
Previous Topic: is it possible to pass named variables through _extra
Next Topic: Re: IDL5 and NT and Alpha

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Nov 30 20:20:18 PST 2025

Total time taken to generate the page: 1.52593 seconds