Consultor Eletrônico



Kbase P145022: How to show what objects are bound to a bindingsource
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   24/04/2009
Status: Unverified

GOAL:

How to show what objects are bound to a bindingsource

GOAL:

How to walk a form and resolve data bindings

FACT(s) (Environment):

Windows
OpenEdge 10.2x

FIX:

It is not possible, from the perspective of the proBindingSource, to determine what controls are bound to its data because the bindingSource simply publishes events when those data are changed or navigated and hold no actual links to the data targets.
In order to resolve the data source for controls on a form it is necessary to walk the control heirarchy of the form and query the dataBindings of each control. Below is a sample that should potentially be called recursively to gather information about the source of data that is shown in controls on an ABL Form.
The following procedure can be called directly from a form, passing THIS-OBJECT in the first parameter and ensuring that the ttControlBinding temp-table is defined in the form or an include file.
/* gatherDataBindingInfo.p */
USING System.Windows.Forms.*.
USING Progress.Data.*.

DEFINE TEMP-TABLE ttControlBinding NO-UNDO
FIELD tcControlName AS CHARACTER
FIELD toControl AS Progress.Lang.Object
FIELD toControlParent AS Progress.Lang.Object
FIELD tcBoundField AS CHARACTER
FIELD tcBoundTable AS CHARACTER
INDEX tcControlName IS PRIMARY UNIQUE tcControlName.

DEFINE INPUT PARAMETER poParentObject AS Progress.Lang.Object NO-UNDO.
DEFINE OUTPUT PARAMETER TABLE FOR ttControlBinding.

DEFINE VARIABLE cParentType AS CHARACTER NO-UNDO.

DEFINE VARIABLE oParentControl AS Control NO-UNDO.

oParentControl = CAST(poParentObject,Control).
RUN traverseControl ( INPUT oParentControl ).

PROCEDURE traverseControl:
DEFINE INPUT PARAMETER poControl AS Control NO-UNDO.

DEFINE VARIABLE cControlName AS CHARACTER NO-UNDO.

DEFINE VARIABLE iControl AS INTEGER NO-UNDO.
DEFINE VARIABLE iControl2 AS INTEGER NO-UNDO.
DEFINE VARIABLE iControlItem AS INTEGER NO-UNDO.

DEFINE VARIABLE oControl AS Control NO-UNDO.
DEFINE VARIABLE oBindingSource AS Progress.Data.BindingSource NO-UNDO.
DEFINE VARIABLE oBinding AS Binding NO-UNDO.
DEFINE VARIABLE oBindingsColl AS BindingsCollection NO-UNDO.
DEFINE VARIABLE oTableSchema AS TableDesc NO-UNDO.

DO iControl = 0 TO poControl:Controls:Count - 1:
oControl = poControl:Controls[iControl].
cControlName = oControl:Name.
oBindingsColl = oControl:DataBindings.

FIND FIRST ttControlBinding
WHERE ttControlBinding.tcControlName EQ cControlName NO-LOCK NO-ERROR.
IF NOT AVAILABLE ttControlBinding THEN
DO iControl2 = 0 TO oBindingsColl:Count - 1 :
oBinding = CAST(oBindingsColl:Item[iControl2],Binding).
oBindingSource = CAST(oBinding:DataSource,Progress.Data.BindingSource).
oTableSchema = CAST(oBindingSource:TableSchema,TableDesc).

CREATE ttControlBinding.
ASSIGN ttControlBinding.tcControlName = cControlName
ttControlBinding.tcBoundTable = oTableSchema:NAME
ttControlBinding.tcBoundField = oBinding:BindingMemberInfo:BindingField
ttControlBinding.toControl = CAST(oControl,Control)
ttControl.Binding.toControlParent = CAST(poControl,Control).

END.
RUN traverseControl ( INPUT oControl ).
END.
END PROCEDURE..