Page 1 of 1

How to clear ordScope()

Posted: Thu Oct 29, 2009 6:03 am
by fafi
Hi.. Greeting From Indonesia

Code: Select all

function main()

use detail 
index on code to detail

SetMyFilter("001")

detail->(dbGotop())
do while !detail->(eof())
     ?detail->code
     detail->(dbSkip())
enddo
... work fine

ClearMyFilter()

detail->(dbGotop())
do while !detail->(eof())
     ?detail->code
     detail->(dbSkip())
enddo
... not work... still locked by scope, the scope is not clear

return nil

function SetMyFilter(cScope)
detail->(ordScope(0,cScope))
detail->(ordScope(1,cScope))
return nil

function ClearMyFilter()
detail->(ordScope(0,NIL))
detail->(ordScope(1,NIL))
return nil

 


.. How to clear my Scope

Regards
Fafi

Re: How to clear ordScope()

Posted: Thu Oct 29, 2009 8:39 am
by Loach
Hello, Fafi !
It has to work!
But you miss ")" in the end of

Code: Select all

detail->(ordScope(0,NIL))

Re: How to clear ordScope()

Posted: Thu Oct 29, 2009 10:03 am
by fafi
Thank's Mr. Loach !

I forgot my ) at the end..

But still not work..

Is OrdScope(0,NIL) correct ? for clear the scope

Regards
fafi

Re: How to clear ordScope()

Posted: Thu Oct 29, 2009 11:08 am
by Loach
This method absolutely correct!
I use OrdScope(0,nil) in all projects and scops are clears...
Try to look on ordkeycount() after the OrdScope(0,NIL). Then you can try to do :

Code: Select all

function ClearMyFilter()
local oldarea:=select()
select datail
ordScope( 0, nil )
ordScope( 1, nil )
SET SCOPE TO 
select(oldarea)
return nil
 

Re: How to clear ordScope()

Posted: Thu Oct 29, 2009 11:16 am
by fafi
Thank's Mr. Loach

I added SET SCOPE TO

It's work now...

Thank's so much

Regards
Fafi

Re: How to clear ordScope()

Posted: Thu Oct 29, 2009 11:54 am
by Loach
Ok, mr. Fafi, but it still not normal :(
SET SCOPE TO it's just analog of ordScope( 0, nil ) and ordScope( 1, nil )...
I think that problem was in work area. In you case

Code: Select all

select datail
ordScope( 0, nil )
ordScope( 1, nil )
select(oldarea)
 
will also work correct IMHO. I don't use SET SCOPE TO. In my projects I use 1->(ordScope( 0, nil )) and never used datail->(ordScope( 0, nil )). But the last one must work correct also. Possible, your program has not time to clear the scopes...

Re: How to clear ordScope()

Posted: Thu Oct 29, 2009 12:24 pm
by Richard Chidiak
I have gone through similar problems in the past

I always close the database and reopen it in order to clear the scopes and it is working just fine

HTH

Richard

Re: How to clear ordScope()

Posted: Thu Oct 29, 2009 2:28 pm
by Enrico Maria Giordano
Richard Chidiak wrote:I have gone through similar problems in the past

I always close the database and reopen it in order to clear the scopes and it is working just fine

HTH

Richard
It is not needed at all. The problem must lies elsewhere.

EMG

Re: How to clear ordScope()

Posted: Thu Oct 29, 2009 4:28 pm
by James Bott
From the ord.ch file:

Code: Select all

#command SET SCOPE TO                 => OrdScope( TOPSCOPE, nil );
                                        ; OrdScope( BOTTOMSCOPE, nil )
So SET SCOPE TO is just setting both top and bottoms scopes to nil. So something else is the problem, or maybe you are interpreting your test results incorrectly (maybe the file's natural order is the same as the indexed order?).

If you want to convice yourself about the above syntax, take a look at the PPO file.

James

Re: How to clear ordScope()

Posted: Fri Oct 30, 2009 8:35 am
by Patrizio
Do you change index between SetMyFilter() and ClearMyFilter() ?

Re: How to clear ordScope()

Posted: Fri Oct 30, 2009 11:52 am
by fafi
Sir ! Try this..

:( not work

Code: Select all

function test()

use detail
index on code tag code to detail

for i := 1 to 100
     detail->(dbappend())
     detail->code   := "001"
     detail->regno := "001"+alltrim(str(i,3))
next

for i := 1 to 100
     detail->(dbappend())
     detail->code   := "002"
     detail->regno := "002"+alltrim(str(i,3))
next

detail->(dbSetOrder("code"))
detail->(ordScope(0,"001"))
detail->(ordScope(1,"001"))
do while !detail->(eof())
    ?detail->regno
    detail->(dbSkip())
enddo

...will display all code with "001"

detail->(ordScope(0,nil))
detail->(ordScope(1,nil))

detail->(dbGotop())
detail->(dbSeek("002"))
... not found.. why ?

 
Regards
Fafi

Re: How to clear ordScope()

Posted: Fri Oct 30, 2009 2:20 pm
by James Bott
Fafi,

Your code works fine here.

James

Code: Select all

// Purpose: Test ordScope(n,nil) clearing the scope

#include "fivewin.ch"

function test()

local i

local aDbf:={}
aadd( aDbf, { "CODE", "C", 3, 0 } )
aadd( aDbf, { "REGNO", "C", 6, 0 } )
dbcreate( 'DETAIL.DBF', aDbf, )

use detail
index on code tag code to detail

for i := 1 to 5
     detail->(dbappend())
     detail->code   := "001"
     detail->regno := "001"+alltrim(str(i,3))
next

for i := 1 to 5
     detail->(dbappend())
     detail->code   := "002"
     detail->regno := "002"+alltrim(str(i,3))
next


//...will display all code with "001" only
detail->(dbSetOrder("code"))
detail->(ordScope(0,"001"))
detail->(ordScope(1,"001"))
detail->(dbgotop())
do while !detail->(eof())
    ?detail->regno
    detail->(dbSkip())
enddo

// Clear scopes
detail->(ordScope(0,nil))
detail->(ordScope(1,nil))

detail->(dbSeek("002"))

msgInfo( detail->(found()) ) // returns .t.

return nil