// Note: uRet1 and uRet2 are nil, but if I enter the very same line in debugger I get the correct value...
SELF:oOwner:Server:GoTop() SELF:oOwner:nNowInFilter:=SELF:oOwner:Server:OrderKeyCount() // ->does not return 1 sometimes
In postinit, I set SELF:oOwner:=uExtra and uExtra is the dbf used in the calling window (an invoice window). When I set the orderscope to "X" (in this message; in reality the actual = an existing invoice number) the orderscope works (we can see that the calling window only contains 1 invoice if e.g. a tabele view is opened) but at the same time OrderKeyCOunt sometimes returns all records of the database. Most of the times both the scope itself and the value to nNowInFilter work fine. I can not see what causes it not to work sometimes and why.
Also, OrderScope() returns the current scope value, so a return value of NIL when there was no previous scope seems OK to me.
And when you execute the expression later in the debugger you will indeed get a value back, because you have just set it with OrderScope()!
Also the GoTop() is not needed. OrderScope() already does that
Finally w.r.t. OrderKeyCount():
There must be an explanation why this sometimes works and sometimes not. But without seeing the whole code I have no idea why.
Maybe some other code is changing the order and you are measuring the OrderKeyCount for this other order that does not have a scope.
I would also advise to include the name of the order that you want to check as parameter to OrderKeyCount() to prevent this.
XSharp Development Team
@Gerhard:sounds clever to me what you do. However, setting the orderscope itself isn't the problem. It's the OrderKeyCount that fails.
I can imagine it's hard to say anything but basically this the code which runs, nothing else. It sets the orderscope, apparently successful, and then does not show the correct orderkeycount - in rare cases. I'll certainly add the index as parameter which may make the difference.
About the GoTop: I added that because the help explicitly says:
Although not shown in the examples below, the GoTop() or some other pointer mechanism, should be used immediately following the OrderScope() method calls to invoke the scope itself.
Added 16:54: to be sure I now do the following: if the amount in OrderKeyCount is not 1 (which it should be in that specific method) I retry with Count(). This is slower but will probably show 1 for sure. At least the user then knows that the database is really filtered, as I show the amount in the filter on the screen.