title: PowerBuilder pasting in tabbed data window
body: <p>I recently started a new job with a company and my first task is to update some quite old software for them.</p>
  
  <p>There is a big back story but basically the software was written in PB8 (around 1997) and no one within the company (including me) has had any experience with PowerBuilder before and as the newbie I have been tasked to update and maintain it until a replacement has been approved and can be developed.</p>
  
  <p>We have the license for PowerBuilder 12.5 so I am using PB12.5 Classic to do everything. The original developer cannot be contacted for support and no documentation exists.</p>
  
  <p>One thing I am trying to understand, that will be a huge help in the future, is how to determine where functions are defined and where variables get their values..</p>
  
  <p>The example I am working on at the moment is the following scenario.
  There is a data window with tabs, named <code>tab_detail</code> each tab displays different <em>whatever little orange men are in the tree list</em>. </p>
  
  <p>One of these are called <code>dw_detail</code> which allows pasting of data. None of the other tabs allow pasting of data, but I would like them to. <code>dw_detail</code> has an event <code>rbuttondown()</code> with the following code in it:</p>
  
  <pre><code>    Window  w_parentwin
  
      If ib_add_mode Or ib_chg_mode Then
          w_parentwin = Parent.GetParent().GetParent()
  
          m_dwpaste   m_pop_paste
          m_pop_paste = CREATE m_dwpaste
  
          m_pop_paste.idw_data = This
  
          If ii_agent_code &gt; 0 And Not IsNull(id_period) And Clipboard() &lt;&gt; "" Then
              m_pop_paste.m_popup.m_paste.Enabled = TRUE
          Else
              m_pop_paste.m_popup.m_paste.Enabled = FALSE
          End If
  
          m_pop_paste.m_popup.PopMenu(w_parentwin.PointerX(), w_parentwin.PointerY())        
  
          DESTROY(m_pop_paste)
      End If
  </code></pre>
  
  <p>When I add that code to the <code>rbuttondown()</code> event of tab number 2 (<code>dw_adjustment</code>) tab 2 now allows paste when I right click within the <code>dw_adjustment</code> data window but the data gets pasted to the fields within the <code>dw_detail</code> tab not the fields on the <code>dw_adjustment</code> tab. </p>
  
  <p>I have tried debugging and stepping through the code but there are thousands of values in the variable window and without the ability to search I cannot find the variables used above and what their values are or why data gets pasted to the <code>dw_detail</code> tab instead of the <code>dw_adjustment</code> tab when I paste into the <code>dw_adjustment</code> tab.</p>
  
  <p>Basically I am looking for any helpful tips on where to look or what the above is doing and why everything pastes to tab 1 instead of the tab I clicked paste in.</p>
  
  <p>If more detail is needed from code from a different location or more information is needed I am happy to provide it.</p>
  
  <p>As suggested by Seki I found the <code>m_popup</code> when double clicked it came up with <code>wf_pastereturn()</code>:</p>
  
  <pre><code>Integer li_idx, li_rows, li_dwrows, li_comm, li_seqno
  String  ls_approval_type
  
  If tab_detail.tabpage_details.dw_detail.RowCount() &gt; 0 Then
      li_idx = 1
      li_dwrows = tab_detail.tabpage_details.dw_detail.RowCount()
  
      Do Until li_idx &gt; li_dwrows
          ls_approval_type = tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx]
          If IsNull(ls_approval_type) or ls_approval_type = "" Then
              tab_detail.tabpage_details.dw_detail.DeleteRow(li_idx)
          Else
              li_idx++
          End If
          li_dwrows = tab_detail.tabpage_details.dw_detail.RowCount()
      Loop
  End If
  
  If li_dwrows &gt; 0 Then
      li_seqno = Long(tab_detail.tabpage_details.dw_detail.Object.seq_no [li_dwrows])
  End If
  li_seqno += 10
  
  
  If Clipboard() &lt;&gt; "" Then
      If tab_detail.tabpage_details.dw_detail.ImportClipboard(1, li_rows, 1, 4, 3) &lt;= 0 Then
          MessageBox("Invalid Data", "Unable to paste!", StopSign!)
          Return -1
      End If
      li_rows = tab_detail.tabpage_details.dw_detail.RowCount()
      li_dwrows++
      For li_idx = li_dwrows To li_rows
          tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx] = trim(tab_detail.tabpage_details.dw_detail.Object.approval_type [li_idx])
          tab_detail.tabpage_details.dw_detail.Object.approval_no [li_idx] = trim(tab_detail.tabpage_details.dw_detail.Object.approval_no [li_idx])
          tab_detail.tabpage_details.dw_detail.Object.agent_code [li_idx] = ii_agent_code
          tab_detail.tabpage_details.dw_detail.Object.period [li_idx] = id_period
          li_comm = f_new_commission(Long(tab_detail.tabpage_details.dw_detail.Object.value_of_work[li_idx]), id_period)
          tab_detail.tabpage_details.dw_detail.Object.levy_payable[li_idx]= &amp;
              inv_rate.of_CalculateLevyPayable (Long(tab_detail.tabpage_details.dw_detail.Object.value_of_work[li_idx]), id_period)
          tab_detail.tabpage_details.dw_detail.Object.comm_deductable [li_idx] = li_comm
          tab_detail.tabpage_details.dw_detail.Object.commission [li_idx] = li_comm
          tab_detail.tabpage_details.dw_detail.Object.seq_no [li_idx] = li_seqno
          li_seqno += 10
          tab_detail.tabpage_details.dw_detail.Object.agent_return_detail_create_date[li_idx] = Today()
          tab_detail.tabpage_details.dw_detail.Object.agent_return_detail_create_user[li_idx] = SQLCA.Logid
      Next
      Clipboard("")
      Return 0
  Else
      Return -1
  End If
  </code></pre>
  
  <p>I modified the function to use the windows <code>SelectedTab</code> property. Data will now paste into the tab but in the wrong input fields. I looked further and the data columns for the <code>ImportClipboard</code> function do not line up. </p>
  
  <p>How is the best way to change the order of the selected database columns?</p>
  
  <p>Here is a screenshot of what I mean by tabs:
  <img src="https://i.stack.imgur.com/emLzT.jpg" alt="enter image description here"></p>
  
  <p>So within the main program window, there are the above tabs, within each tab (where the input fields are) there is a data window labelled with the <code>dw_</code> prefix.</p>
  
  <p>Thanks heaps for your help.</p>