Source Code For: Debugging DataWindows - Live!
Vol 7, Issue 2 p.31
Listing 1
// Clicked for rb_all// Clicked for rb_original. int li_Arg, li_NumArgs, li_Pos, li_Col, li_Cols string ls_sql_syntax, ls_dw_syntax, ls_error, ls_Arg string ls_ArgNames[], ls_ArgTypes[], ls_TmpSyntax u_dw ldw_remote n_cst_string lnv_string if IsNull(idw_Requestor) then return if not IsValid(idw_Requestor) then return SetPointer(hourglass!) ls_sql_syntax = idw_Requestor.Describe( & 'DataWindow.Table.Select') // Make sure we have a database connection. if SQLCA.DBHandle () = 0 then MessageBox ("All Columns:", & "Transaction not connected!", StopSign!) rb_original.checked = true return end if // Make sure we have a valid SQL statement. if Pos (ls_sql_syntax, "PBSELECT") > 0 then idw_Requestor.SetTransObject (SQLCA) ls_sql_syntax = idw_Requestor.Describe( & 'DataWindow.Table.Select') end if // Replace any args so that we don't get prompted. ldw_remote = idw_Requestor ldw_remote.of_SetBase (true) ldw_remote.inv_base.of_dwArguments (ls_ArgNames, & ls_ArgTypes) // Loop through the arguments. li_NumArgs = UpperBound (ls_ArgNames) ls_sql_syntax = lnv_string.of_GlobalReplace ( & ls_sql_syntax, "~~~"", "~"") for li_Arg = 1 to li_NumArgs // Copy the SQL so we can search it in lower case. ls_TmpSyntax = Lower (ls_sql_syntax) li_Pos = Pos (ls_TmpSyntax, ":" + ls_ArgNames[li_Arg]) if li_Pos > 0 then choose case ls_ArgTypes[li_Arg] // CHARACTER DATATYPE CASE "string" ls_Arg = "''" // Empty string. // DATE DATATYPE CASE "date" ls_Arg = "'1900-01-01'" // Empty date. // DATETIME DATATYPE CASE "datetime" // NOTE: This is a simplification, // and won't work with all DBMSs. ls_Arg = "'1900-01-01'" // Numeric datatypes CASE "decimal", "number", "long", "ulong" ls_Arg = "0" // Default to zero. // TIME DATATYPE CASE "time", "times" ls_Arg = "'12:00:00'" // Default to noon. end choose // Change the SQL syntax. ls_sql_syntax = & Left (ls_sql_syntax, li_Pos - 1) + & ls_arg + & Mid (ls_sql_syntax, li_Pos + & Len (ls_ArgNames[li_Arg]) + 1) end if next // Get the DataWindow syntax for this ls_dw_syntax = SQLCA.SyntaxFromSQL( & ls_sql_syntax, "Style(Type= Grid )",ls_error) if Len(ls_error) > 0 then MessageBox("SyntaxFromSQL:",ls_error) return end if // Put this DataWindow in the two DW controls. dw_requestorview.ShareDataOff() dw_requestorview.Create(ls_dw_syntax,ls_error) if len(ls_error) > 0 then MessageBox("Create:",ls_error) return end if dw_requestorduplicate.Create(ls_dw_syntax,ls_error) if len(ls_error) > 0 then MessageBox("Create:",ls_error) return end if idw_Requestor.ShareData(dw_requestorview) // Make sure the data is editable. // NOTE: Only the primary buffer will be editable. ls_Arg = dw_requestorview.Describe("#1.TabSequence") if ls_Arg <> "10" then // Loop thru the cols and assign a tab order. li_Cols = Integer (dw_requestorview.Describe ( & "DataWindow.Column.Count")) for li_Col = 1 to li_Cols dw_requestorview.Modify ( & "#" + String (li_Col) + ".TabSequence = " + & String (li_Col)) next end if // Update the statistics and the buffer. parent.Event pfc_PropertyStats () if rb_primary.checked then Parent.Event pfc_PropertyBufferChanged(Primary!) elseif rb_deleted.checked then Parent.Event pfc_PropertyBufferChanged(Delete!) else Parent.Event pfc_PropertyBufferChanged(Filter!) end if Listing 2
// Function of_LoadChild (long al_row): // Load a child DW object into the detail DWs. Datawindowchild ldwc_temp int li_rc string ls_Column, ls_DataObject if IsNull (al_row) or al_row <= 0 or & al_row > dw_children.RowCount () then return Ð1 end if // Get the column and datawindow object. ls_Column = dw_children.GetItemString (al_row, & "colname") ls_DataObject = dw_children.GetItemString ( & al_row, "dataobject") // Get a reference to the child datawindow. Li_rc = idw_requestor.GetChild (ls_Column, ldwc_temp) if li_rc < 0 then return -1 // Set the DataObject of the bottom datawindow. dw_requestorview.ShareDataOff () dw_requestorview.DataObject = ls_DataObject dw_requestorduplicate.DataObject = ls_DataObject li_rc = ldwc_temp.ShareData (dw_requestorview) this.Event pfc_PropertyBufferChanged( & idwb_CurrentBuffer) // Update the onscreen stats. this.Event pfc_PropertyStats() return li_rc Listing 3
// Se// Event pfc_PropertyStats: t the text for the radio buttons to keep // track of row counts. if dw_requestorview.DataObject = "" then return 0 rb_primary.Text = & string(dw_requestorview.RowCount()) + & " &Primary" rb_filtered.Text = & string(dw_requestorview.FilteredCount()) + & " &Filtered" rb_deleted.Text = & string(dw_requestorview.DeletedCount()) + & " &Deleted" Return 1 Listing 4
// Event pfc_PropertyPopulate: // Load the child DW objects into the master DW. int li_Col, li_Cols long ll_row string ls_Columns[], ls_Describe, ls_DDDWName // Use the base DataWindow service to get a list // of the columns in the DataWindow. if not IsValid (idw_requestor.inv_base) then idw_requestor.of_SetBase (true) end if li_Cols = idw_requestor.inv_base.of_GetObjects ( & ls_Columns, "column", "*", false) // Loop through the columns. for li_Col = 1 to li_Cols // Get the edit style. ls_Describe = idw_requestor.Describe ( & ls_Columns[li_Col] + ".Edit.Style") // Only dddws need apply. if ls_Describe <> "dddw" then continue // Get the name of the dddw. ls_DDDWName = idw_requestor.Describe ( & ls_Columns[li_Col] + ".dddw.Name") if ls_DDDWName = "!" or ls_DDDWName = "?" or & Trim (ls_DDDWName) = "" then continue // Insert this dddw into the list. ll_row = dw_children.InsertRow(0) dw_children.SetItem (ll_row, "colname", & ls_Columns[li_Col]) dw_children.SetItem (ll_row, "dataobject", & ls_DDDWName) next if dw_children.RowCount() > 0 then this.of_LoadChild (1) end if