[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: Usage of BIND, REFERENCE-ONLY and BY-REFERENCE with ProDataSets & temp-tables

Status
Not open for further replies.
M

marian.edu

Guest
[quote user="Tim Kuehn"] Strictly speaking - BIND and BY-REFERENCE don't pass anything but a TT reference. [/quote] That probably just make it more confusing, it's really not the same thing and albeit I've used BIND before (damn it's so tempting, much like static) now I see it more like one of those features that creates anti-patterns :( [quote user="Tim Kuehn"] BIND permanently associates the target instance's TT references with the source's TT reference. [/quote] 'Permanently' there is more relative, if the reference you bind to is dynamic that will just go away when deleted. Oddly enough for a static object that will remain valid until everyone that has a reference to it is still alive, even if the class/procedure that instantiated it was deleted... much like a shared variable :( Probably the only use-case for BIND is when you need to wrap a table/dataset in an object - either a 'request' object received over an appsrv call or coming from the data access layer. One way to get around this is to inject the data structure in the constructor using by-reference and store only it's handle then use that 'reference' by passing it as table/dataset handle to internal methods using by-reference. That way you always know if your reference is still valid and you can use static data access in internal methods. Why table/dataset-handle parameters needs by-reference I have no idea, for me this should be the default for 'handles'. Input-output could, arguably, also default to by-reference although the only difference is that if the routine throws an error the original data structure remains as it was before the call. class MyRequest: {ttCustomer.i &reference-only=reference-only} define private variable bindTableHandle as handle no-undo. constructor public MyRequest ( table for ttCustomer ): bindTableHandle = temp-table ttCustomer:handle. end constructor. method public character getName (custNum as integer): if valid-handle(bindTableHandle) then return getName(custNum, table-handle bindTableHandle by-reference). end method. method protected character getName (custNum as integer, table for ttCustomer): for each ttCustomer where ttCustomer.custNum = custNum: return ttCustomer.name. end. end method. end class.

Continue reading...
 
Status
Not open for further replies.
Top