Page 1 of 2
How Open the same dbf
Posted: Tue Dec 25, 2018 4:41 pm
by Silvio.Falconi
I need to open the same dbf but with filter different
My archive
Code: Select all | Expand
DbCreate(cDbfPath+'Servizi', { { "id" , "C", 4, 0 },;
{ "name" , "C", 30, 0 },;
{ "breve" , "C", 10, 0 },;
{ "price" , "N", 9, 2 },;
{ "image" , "C", 30, 0 },;
{ "struttura", "C",60, 0 },;
{ "unit" , "N", 4, 0 },;
{ "a4" , "L", 1, 0 },;
{ "pos" , "L", 1, 0 },;
{ "multiple", "L", 1, 0 },;
{ "islock" , "L", 1, 0 },;
{ "ordine" , "N", 2, 0 } }, "DBFCDX", .T., "DB" )
cDbfPath := cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
first area set filter to multiple:=.f.
second area set filter to multiple:=.t.
before I resolved making two arrays but Now I'thinking is not good because I have problems when I manage the records
I must open the dbf and use it
How I resolve ?I tried with
use servizi alias oServiziSingoli
set filter to oServiziSingoli->multiple=.f.
oServiziSingoli->(dbgotop())
use servizi alias oServiziMultipli
set filter to oServiziMultipli->multiple=.t.
oServiziMultipli->(dbgotop())
but not run
Re: How Open the same dbf
Posted: Tue Dec 25, 2018 7:57 pm
by nageswaragunupudi
Code: Select all | Expand
USE SERVIZI NEW SHARED ALIAS "SINGL"
SET FILTER TO FIELD->MULTIPLE=.F.
SINGL->(DBGOTOP())
USE SERVIZI NEW SHARED ALIAS "MULTI"
SET FILTER TO FIELD->MULTIPLE=.T.
MULTI->(DBGOTOP())
Re: How Open the same dbf
Posted: Tue Dec 25, 2018 8:05 pm
by Silvio.Falconi
run ok . thanks
Nages,
I have the dbf in a folder
cDbfPath := cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
USE cDbfPath+SERVIZI NEW SHARED ALIAS "SINGL"
SET FILTER TO FIELD->MULTIPLE=.F.
SINGL->(DBGOTOP())
make error !!!
If I use
SE cDbfPath+SERVIZI not run
f I insert .\data\servizi run ok
strange ...
Re: How Open the same dbf
Posted: Tue Dec 25, 2018 8:15 pm
by nageswaragunupudi
What error?
Re: How Open the same dbf
Posted: Tue Dec 25, 2018 8:23 pm
by Silvio.Falconi
I have dbfs/cdx into a Folder
cDbfPath := cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
I made
USE cDbfPath+SERVIZI NEW SHARED ALIAS "SINGL"
SET FILTER TO FIELD->MULTIPLE=.F.
SINGL->(DBGOTOP())
USE cDbfPath+SERVIZI NEW SHARED ALIAS "MULTI"
SET FILTER TO FIELD->MULTIPLE=.T.
MULTI->(DBGOTOP())
give me error
Code: Select all | Expand
Path and name: C:\Work\Errori\tdata_test\test.Exe (32 bits)
Size: 3,826,688 bytes
Compiler version: Harbour 3.2.0dev (r1703231115)
FiveWin version: FWH 18.11
C compiler version: Borland/Embarcadero C++ 7.0 (32-bit)
Windows version: 6.2, Build 9200
Time from start: 0 hours 0 mins 0 secs
Error occurred at: 25-12-2018, 21:22:57
Error description: (DOS Error 3) DBFCDX/1001 Errore in apertura: cDbfPath+SERVIZI.dbf
Re: How Open the same dbf
Posted: Tue Dec 25, 2018 8:57 pm
by nageswaragunupudi
Re: How Open the same dbf
Posted: Tue Dec 25, 2018 9:00 pm
by Silvio.Falconi
ooppsss sorry ...
USE &(cDbfPath+cDbf+".dbf") ;
INDEX &(cDbfPath+cDbf+".cdx") ;
ALIAS &(cAlias) NEW SHARED
Re: How Open the same dbf
Posted: Tue Dec 25, 2018 9:04 pm
by nageswaragunupudi
Also instead of
Code: Select all | Expand
cDbfPath := cFilePath(GetModuleFileName( GetInstance() )) + "Data\"
This is a lot simpler
And this is the simplest
Re: How Open the same dbf
Posted: Tue Dec 25, 2018 9:09 pm
by nageswaragunupudi
Silvio.Falconi wrote:ooppsss sorry ...
USE &(cDbfPath+cDbf+".dbf") ;
INDEX &(cDbfPath+cDbf+".cdx") ;
ALIAS &(cAlias) NEW SHARED
NO.
Do not put &.
Re: How Open the same dbf
Posted: Wed Dec 26, 2018 5:15 pm
by Silvio.Falconi
Rao,
your sample
sometmes the first xbrowse is hided when I resize the dialog ...it is not stable !!!!
Re: How Open the same dbf
Posted: Thu Dec 27, 2018 6:22 pm
by TimStone
Silvio,
Instead of filters, create indexes. It is MUCH faster. Also, whenever you add records, the indexes are automatically updated.
Open the first alias with the index for .t., and open the second alias with the index for .f.
Filters are always slower.
Re: How Open the same dbf
Posted: Fri Dec 28, 2018 1:37 am
by Silvio.Falconi
tried not run
I also tried with diferent arrays I thinked cold be more fast
then the problem is to add/mod/can record for each xbrowse and upate the archive
Now run ok only the first xbrowse on resizin sometimes is hided...i not Know why
two Xbrowse
Add/mod single service
add/mod Multiple service
But I see all more more instable I not Know why
Re: How Open the same dbf
Posted: Fri Dec 28, 2018 10:14 pm
by James Bott
It is this simple with database objects.
oServizi1 := TServizi():New()
oServizi1:setFilter( "multiple = .f.")
oServizi2 := TServizi():New()
oServizi2:setFilter( "multiple = .t.")
However, filters are really impractical for all but very small databases. As Tim stated, indexes are much better. To use indexes (in this case), just create one for True and one for False.
oServizi1 := TServizi():New()
oServizi1:setFilter( "MFALSE")
oServizi2 := TServizi():New()
oServizi2:setFilter( "MTRUE")
Very fast, new records are automatically added.
James
Re: How Open the same dbf
Posted: Sat Dec 29, 2018 6:28 pm
by TimStone
James,
If tServiz opens a database object, as part of it's code, I use the setorder() in it's code.
If the first index is 1 ( for the true records ), and the second index is 2 ( for the false records ), I would open the two views as:
oServiz1 := TServiz():New(1)
oServiz2 :- TServiz():New(2)
I use dual browses on the same dialog all of the time within my programming, though it's usually two different databases. However, that doesn't matter. In this case the first browse is created with oServiz1 as the DATASOURCE, and the second one uses oServiz2.
I have so many of these running, and they NEVER fail.
Tim
Re: How Open the same dbf
Posted: Tue Jan 01, 2019 12:17 am
by James Bott
Tim,
When I first read your message I was confused as to why you were restating what I said in my previous message. Then I noticed what I had written in my previous message:
oServizi1 := TServizi():New()
oServizi1:setFilter( "MFALSE")
oServizi2 := TServizi():New()
oServizi2:setFilter( "MTRUE")
These lines were supposed to say SetOrder() not SetFilter(), where the passed parameter is the TAG name of the order.
oServizi1 := TServizi():New()
oServizi1:setOrder( "MFALSE")
oServizi2 := TServizi():New()
oServizi2:setOrder("MTRUE")
Of course, one could use the number of the order like you did, but I find it more difficult to remember and not as clear to read later, as the tag name.
For others reading this, the indexes the indexes would be built using a condition:
INDEX ON <expKey> [TAG <cOrderName>] [TO <cOrderBagName>]
[FOR <lCondition>] [ALL]
INDEX ON multiple TAG "MTRUE" TO Servizi FOR Multiple == .T.
INDEX ON multiple TAG "MFALSE" TO Servizi FOR Multiple == .F.
Each index actually contains only the desired records so it acts like a filter but has the speed of an index.