I wonder what the best technique would be and the advantages of 1 of the 2
Often, I need to use the same database in more than one lookup action or update action.
1. I can change the index order, but than I also have to keep track of resetting it back and at the correct position
2. I can open de database in more aliases and use different browses and lookups with these aliases ?? Can I get issues with the CDX file ?
And we can use Oop (James), smaller parts are converted somethimes in this way.
But just out of interest... witch is used more often here ( 1 or 2) ?
In 1 : The first time, sometimes is with a relation set to ... , and when the database order is changed, the relation is broken. (I believe this is standard in FW)
Program techniques : change indexorder or use aliases
- Marc Venken
- Posts: 727
- Joined: Tue Jun 14, 2016 7:51 am
Program techniques : change indexorder or use aliases
Marc Venken
Using: FWH 20.08 with Harbour
Using: FWH 20.08 with Harbour
- Enrico Maria Giordano
- Posts: 7355
- Joined: Thu Oct 06, 2005 8:17 pm
- Location: Roma - Italia
- Contact:
Re: Program techniques : change indexorder or use aliases
Personally, I'm using both, depending on the specific situation.Marc Venken wrote:But just out of interest... witch is used more often here ( 1 or 2) ?
No, it is standard in xBase languages.Marc Venken wrote:In 1 : The first time, sometimes is with a relation set to ... , and when the database order is changed, the relation is broken. (I believe this is standard in FW)
EMG
- James Bott
- Posts: 4654
- Joined: Fri Nov 18, 2005 4:52 pm
- Location: San Diego, California, USA
- Contact:
Re: Program techniques : change indexorder or use aliases
Marc,
You gave me a laugh when I saw your message directed at me-you knew I would say OOP. Good, at least you remember.
Note that back in Clipper era with 16bit computers without much memory we were limited as to how many files we could have open at one time. This rarely an issue now. so you can open as many files as you need usually. You will, however, run into speed issues when the PC has limited RAM.
OOP databases open a new copy of a database each time they are initiated. So you may have several copies of the same database open at once.
oCustomer1:= TCustomer():new()
oCustomer2:= TCustomer():new()
Without using OOP, if you try to open one database and use it in several routines by passing it around, then you are going to have to save and restore it's state in each routine that changes the state. That means index , index order, current recno, filter, relation, etc. I tried this once but it was way too complicated.
With OOP, it just takes one line of code to open a new copy of a database--and no save and restore needed. Actually, it could be more than one database, for instance with a sales order object. You have a customer, invoice header and invoice line items databases, and two of them are related. Still one line of code to open it:
oSalesOrder:= TSalesOrder():new()
James
Simplicity is the ultimate sophistication. ~Leonardo DaVinci
You gave me a laugh when I saw your message directed at me-you knew I would say OOP. Good, at least you remember.
Note that back in Clipper era with 16bit computers without much memory we were limited as to how many files we could have open at one time. This rarely an issue now. so you can open as many files as you need usually. You will, however, run into speed issues when the PC has limited RAM.
OOP databases open a new copy of a database each time they are initiated. So you may have several copies of the same database open at once.
oCustomer1:= TCustomer():new()
oCustomer2:= TCustomer():new()
Without using OOP, if you try to open one database and use it in several routines by passing it around, then you are going to have to save and restore it's state in each routine that changes the state. That means index , index order, current recno, filter, relation, etc. I tried this once but it was way too complicated.
With OOP, it just takes one line of code to open a new copy of a database--and no save and restore needed. Actually, it could be more than one database, for instance with a sales order object. You have a customer, invoice header and invoice line items databases, and two of them are related. Still one line of code to open it:
oSalesOrder:= TSalesOrder():new()
James
Simplicity is the ultimate sophistication. ~Leonardo DaVinci
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
- nageswaragunupudi
- Posts: 8017
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Contact:
Re: Program techniques : change indexorder or use aliases
This is easy
No problems.2. I can open de database in more aliases and use different browses and lookups with these aliases ?? Can I get issues with the CDX file ?
Regards
G. N. Rao.
Hyderabad, India
G. N. Rao.
Hyderabad, India
- Marc Venken
- Posts: 727
- Joined: Tue Jun 14, 2016 7:51 am
Re: Program techniques : change indexorder or use aliases
ITEMS->( FW_DBLOOKUP( 101, "ITEMCODE", { || FIELD->QTY -= nOldQty } )* New: function FW_DBFLOOKUP( uVal, [cOrder], bcRetExprn ) --> uResult
uVal : Value / Expression to be lookedup ( seek or locate )
cOrder : OrderName for seek. Or field name for locate. Omit if uVal
is an expression
bcRetExpr: codeblock/string: Expression to evaluate
Examples:
CUSTOMER->( FW_DBFLOOKUP( 108, "ID", "AGE" ) ) --> nAge of ID 108
CUSTOMER->( FW_DBFLOOKUP( 99, "ID", "FIELD->SALARY += 100" ) ) -->
Salary field is incremented and written to table and returns the value
ITEMS->( FW_DBLOOKUP( 101, "ITEMCODE", { || FIELD->QTY -= nOldQty } )
ITEMS->( FW_DBLOOKUP( 103, "ITEMCODE", { || FIELD->QRY += nNewQty } )
STATES->( FW_DBLOOKUP( 10, 0, "FIELD->NAME" ) ) // at recno 10
Original recno() and order are restored and any previous locks are
left intact before returning.
Reurn value NIL indicates failure
source: \fwh\function\dbffuns2.prg
ITEMS->( FW_DBLOOKUP( 103, "ITEMCODE", { || FIELD->QRY += nNewQty } )
This function handles also everything not ?? (no need to extra open the dbf in a new alias)
This sample in use with a bchange function call from Xbrowse should work not ? (will test it later)
ITEMS->( FW_DBLOOKUP( obrw:code:value, "ITEMCODE", { || FIELD->GROEP = oBrw:groep:value } ) )
I suppose that we can also change more than one item with this code ? { || FIELD->GROEP = oBrw:groep:value, FIELD->DATE = date() } or maybe better call a function and change the data insite the function ?
This function supposes that the file is already open... Can we also let it open the dbf when it is not yet open before calling the function ?
Marc Venken
Using: FWH 20.08 with Harbour
Using: FWH 20.08 with Harbour