Return data from every object in a dbView: Difference between revisions
(New page: 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 ...) |
Hsymington (talk | contribs) m (Added to Tutorials category) |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
====Use an array to hold the object ID==== | ====Use an array to hold the object ID==== | ||
You can use an array to hold the ObjectID of each object. Then | You can use an array to hold the ObjectID of each object. Then loop thru the array and ask the property of each object. | ||
<source lang="dataflex"> | |||
// outside the dbview: | // outside the dbview: | ||
Object oMyViewObjects is an Array | Object oMyViewObjects is an Array | ||
Line 20: | Line 20: | ||
Set Value of hoArray Item (Item_Count(hoArray)) to (Object_ID(Self)) | Set Value of hoArray Item (Item_Count(hoArray)) to (Object_ID(Self)) | ||
End_Procedure | End_Procedure | ||
</source> | |||
====Using Broadcast send==== | ====Using Broadcast send==== | ||
Line 31: | Line 32: | ||
In global scope: | In global scope: | ||
<source lang="dataflex"> | |||
Procedure CallbackReportExistance For cObject Integer iMsg Handle hoId | Procedure CallbackReportExistance For cObject Integer iMsg Handle hoId | ||
Send iMsg to hoID Self | Send iMsg to hoID Self | ||
End_Procedure // CallbackReportExistance | End_Procedure // CallbackReportExistance | ||
</source> | |||
In local scope: | In local scope: | ||
<source lang="dataflex"> | |||
Procedure AddObject Handle hoObject | Procedure AddObject Handle hoObject | ||
Move hoObject to ghoObject[SizeOfArray(ghoObject)] | Move hoObject to ghoObject[SizeOfArray(ghoObject)] | ||
Line 42: | Line 46: | ||
Broadcast Send CallbackReportExistance of hoView msg_AddObject Self | Broadcast Send CallbackReportExistance of hoView msg_AddObject Self | ||
</source> | |||
====Using Broadcast get==== | ====Using Broadcast get==== | ||
Line 50: | Line 55: | ||
Something like this: | Something like this: | ||
<source lang="dataflex"> | |||
Procedure AddProperty ByRef Handle[] hoaObject ByRef Integer[] iaProperty | Procedure AddProperty ByRef Handle[] hoaObject ByRef Integer[] iaProperty | ||
Move Self to hoaObject[SizeOfArray(hoaObject)] | Move Self to hoaObject[SizeOfArray(hoaObject)] | ||
Line 56: | Line 62: | ||
Broadcast Send MyProcedure | Broadcast Send MyProcedure | ||
</source> | |||
====External links==== | ====External links==== | ||
This how-to was taken straight from | [http://www.sture.dk/wasp/threadreport.asp?ThreadId=40753 This how-to was taken straight from thread 40753] | ||
http://www. | |||
Another approach: | |||
[http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2363 HOWTO: Enumerate all child objects of a (db)View] | |||
[[Category:How To]] | |||
[[Category:Tutorials]] |
Latest revision as of 12:46, 25 March 2020
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