0

I am trying to configure a combo box so that it shows a default value and does not show empty.

The structure is as follows:

`ccmbDynamic: cmbcombo
-List Initialization
*Message Action
 *On PAM_Create
 -Set nMyObjectID = 1
 -Call clsDynamicListPopulateFull('Table_name', 'code_id', 'Description', 'Condition Where', 
                                  'code_id', 1, CMD_Description, DT_Number, CMD_ForceFetch)
 -Call SalsendMsg(cmbcombo, SAM_Click, 0, 0)

 *On PAM_SAM_Click
 -Call IntSqlInmediately ('SELECT code_id FROM Table_name WHERE Condition')`

Does anyone know what process I am doing incorrectly? The queries return the correct information, but the selection is not reflected in the combo (The selected default), only when I click is that the information is seen, I need it to be seen before the click, some help on this?

toyota Supra
  • 3,181
  • 4
  • 15
  • 19
erik1520
  • 1
  • 1

1 Answers1

0

Its not clear what is happening at class level ( ccmbDynamic ) as you don't show it.

In fact it's not clear what any of this code is doing.

But a much easier way to Populate a combo is to use SalListPopulate ( hWndCombo, hSql, 'Your select Statement' ), and this will fetch from the dB and fill the combo at the same time. If you then want to select a specific entry in the combo, call SalListSetSelect ( hWndCombo, nIndexToSelect ) e.g. SalListSetSelect ( hWndCombo, 0 ) to select the first entry. e.g.

On SAM_Create
  If SalListPopulate( hWndCombo, hSql, 'SELECT code_id FROM Table WHERE 
                                       Condition' )
     ! Set list box selection to the first item.
     ! If you specify -1, SQLWindows deselects the selected entry
     Call SalListSetSelect( hWndCombo, 0 ) 

                                                                                                                                                           

p.s. Unrelated to the question, but worth mentioning.... I do hope your user function IntSqlInmediately does not actually call the builtin function SqlImmediate() ( you'd best check this out ) - as this was depricated many years ago by Gupta in favour of SqlPrepareAndExecute(hSql, 'Your select Statement') followed by SqlFetchNext(hSql, nFetched). The reason SqlImmediate() was depricated, was that programmers were too lazy to release the internal handle connected by the function, by then calling SqlClearImmediate (). So if you insist on using SqlImmediate() - remember to follow with SqlClearImmediate() . Otherwise those internal handles will buildup ad-infinitum until you get a GPF.

Steve Leighton
  • 790
  • 5
  • 15
  • I can confirm that Call SalListSetSelect( hWndCombo, 0 ) is the way to show the first entry in the list. – Thomas Uttendorfer Aug 13 '23 at 10:27
  • Steve, I don't get a GPF when using SqlImmediate(...) e.g. 10.000 times in a row. Internally TD connects ONE cursor for SqlImmediate(..) and keeps it connected until you issue SqlClearImmediate(..) or until the end of the programm. So there is not a real resource problem here. I don't understand why Gupta says the function is deprecated. But you really should know how to use it because of performance issues. You should not use it just for lazyness. – Thomas Uttendorfer Aug 13 '23 at 10:31
  • Hello Thomas Thanks for the insight - and I agree with the one internal handle, but the GPF point is mute, as it completely depends on the communication protocol being used. Try using SqlImmediate ( or SqlExists ) with OLEdB - you will get a GPF regardless ( or 'invalid cursor' at least ) . Also I was trying to point out that using SqlImmediate is bad style - not to be encouraged, as the Sql will be re-PreparedAndExecuted every time it is called - even if already Prepared. And in reality, a Handle pool with pre-Connected handles should be being used I believe. – Steve Leighton Aug 15 '23 at 06:25