Page 1 of 1

wbrowse.prg function nwrows returning huge no

Posted: Wed Nov 15, 2006 10:18 am
by peterk
Hi Antonio

I have a situation where wbrowse.prg method nRowCount is returning 53000 rows! This causes one of my browses on a dbf (which has +- 160,000 records in it) to take ages to open.

nRowCount calls nwrows which calls GetWindowRows (extracted below)

nRowCount should obviously never return more than the no of rows a browse could theoretically display with its font - say 100

It only happens on the 1st call to nRowCount (in our case from upstable), which causes UpStable to skip through 53000 records. Thereafter it returns the correct no of rows (39)

The font object in Wbrowse has a valid handle and seems fine.

Can you comment on what might be causing this ?

Thanks
Peter



*********************************
WORD GetWindowRows( HWND hWnd, HDC hDC, HFONT hFont )
{
TEXTMETRIC tm;
RECT rct;
WORD wRows;
BOOL bDCDestroy = FALSE;
HFONT hOldFont;

if( ! hDC )
{
bDCDestroy = TRUE;
hDC = GetDC( hWnd );
}

if( hFont )
hOldFont = ( HFONT ) SelectObject( hDC, hFont );

GetTextMetrics( hDC, &tm );
tm.tmHeight += 1;

GetClientRect( hWnd, &rct );
wRows = ( rct.bottom - rct.top ) / tm.tmHeight;

if( hFont )
SelectObject( hDC, hOldFont );

if( bDCDestroy )
ReleaseDC( hWnd, hDC );

return wRows;
}

//----------------------------------------------------------------------------//

CLIPPER NWROWS( PARAMS ) // hWnd, hDC, hFont
{
_retni( GetWindowRows( ( HWND ) _parnl( 1 ), ( HDC ) _parnl( 2 ),
( HFONT ) _parnl( 3 ) ) );
}

Posted: Wed Nov 15, 2006 12:10 pm
by Antonio Linares
Peter,

Are you calling the UpStable method before the browse is created by Windows ? (oBrw:hWnd != 0 )

Is it placed on a dialog ? If so, please call UpStable from here:

ACTIVATE DIALOG oDlg ON INIT oBrw:UpStable()

Posted: Wed Nov 15, 2006 1:24 pm
by peterk
Antonio

Yes you are correct! I am calling upstable while the Brw ::hWnd is 0

May I suggest you change wBrowse nRowCount method as follows to prevent other users wasting time on the same issue

METHOD nRowCount() INLINE ;
if(::hWnd > 0, nWRows( ::hWnd, 0, If( ::oFont != nil, ::oFont:hFont, 0 ) ) - 1, 0)

Thanks for the assistance
Peter

Posted: Wed Nov 15, 2006 1:29 pm
by Antonio Linares
Peter,

Changed, thanks.

Please use ::hWnd != 0 instead of ::hWnd > 0