Return data from every object in a dbView

From DataFlex Wiki
Jump to navigationJump to search

How would one ask any object in a dbView for the value of a specific property?

Use an array to hold the object ID

You can use an array to hold the ObjectID of each object. Then loop thru the array and ask the property of each object.

 // outside the dbview:
 Object oMyViewObjects is an Array
    // 0 = ObjectID of each object
 End_Object
 // inside the dbview
 Procedure Activating returns Integer
    Handle hoArray
    Move (oMyViewObjects(Self)) to hoArray
    Send Delete_Data of hoArray
    Broadcast Recursive Send DoRegisterYourself hoArray
 End_Procedure
 // inside the objects you want to get a property from:
 Procedure DoRegisterYourself Handle hoArray
    Set Value of hoArray Item (Item_Count(hoArray)) to (Object_ID(Self))
 End_Procedure

Using Broadcast send

If you really want to scan all objects, you use Broadcast. If you do Broadcast Send of an object, all child objects will also get the message. In order to get two way communication with the objects you first need to hack a callback procedure into every object no matter which class they are. After this, you Broadcast Send this procedure, and let all objects callback to you. You can then get the property, or same them to an array, or what every you want.

In global scope:

 Procedure CallbackReportExistance For cObject Integer iMsg Handle hoId
    Send iMsg to hoID Self
 End_Procedure // CallbackReportExistance

In local scope:

 Procedure AddObject Handle hoObject
    Move hoObject to ghoObject[SizeOfArray(ghoObject)]
 End_Procedure // AddDD
 
 Broadcast Send CallbackReportExistance of hoView msg_AddObject Self

Using Broadcast get

There's also a broadcast get available, which usually stops at the first time there's a non-zero response. But then there's also a nostop option, which suppresses that behaviour. However, I'm not sure how to get the value of each individual funtion call. (getting property values are also function calls).

By doing a Broadcast Send of a procedure with a Byref Array parameter I could get everyone to fill in their return values there. Something like this:

 Procedure AddProperty ByRef Handle[] hoaObject ByRef Integer[] iaProperty
    Move Self to hoaObject[SizeOfArray(hoaObject)]
    Get piProperty to iaProperty[SizeOfArray(iaProperty)]
 End_Procedure // AddProperty

 Broadcast Send MyProcedure

External links

This how-to was taken straight from thread 40753

Another approach: HOWTO: Enumerate all child objects of a (db)View