Page 1 of 1

dc_setrelation problem

Posted: Thu Feb 24, 2011 8:01 am
by BruceN
I have used dc_setrelation numerous times and MOST times it works perfectly. Occasionally it doesn't and I can't tell what stupid thing I'm doing differently (I'm assuming the problem is with me and not Roger's code).

I'm trying now to use it on a report. I have the INVOICES.DBF file open (indexed and with a filter)
index is on i_prodid field and filter is: DbSetFilter( {||substr(i_custid,1,1) <> '|'} )

then right after that I have:
if o_products(.f.,.t.) // open PROUCTS.DBF file
dbsetorder(1) // products->prodid
dbgotop()
dc_SetRelation("invoices", {||invoices->i_prodid} )

When I show data from products file, I always get the data from the first record (in indexed order)
Have same issue if I open invoices and index on date field.

Almost forgot: Alaska 355 and express 244
As always...

thanks

Re: dc_setrelation problem

Posted: Thu Feb 24, 2011 8:47 am
by skiman
Hi,

Maybe a dbskip(0) will help after setting your relation.

I'm never using it, I always do a dbseek().

Re: dc_setrelation problem

Posted: Thu Feb 24, 2011 8:55 am
by BruceN
thanks for the thought, but it didn't work.

I figured the dc_setrelation would be slicker and faster than changing workarea, doing a dbseek, then changing back for every record.

Re: dc_setrelation problem

Posted: Thu Feb 24, 2011 9:04 am
by rdonnay
Can you write a small sample program and send it to me?

Include your databases.

Re: dc_setrelation problem

Posted: Thu Feb 24, 2011 9:38 am
by skiman
Changing workarea :?:

What about products->(dbseek( invoices->art_number))

Or in a browse
Dcbrowsecol data {|| products->(dbseek( invoices->art_number)) , products->description }
Dcbrowsecol data {|| products->brand }

If there is another browsecolumn with data from products, you don't need another seek.

Re: dc_setrelation problem

Posted: Thu Feb 24, 2011 10:21 am
by BruceN
Tried to post this 3 times....

Never knew that 'trick' [ products->(dbseek( invoices->art_number)) ].

When our partner/programmer retired unexpectedly a few years ago wife and I had to learn everything on our own. Only way we could learn was looking at the code and copying ideas/syntax, etc.

Way it was always done in our code was:
select PRODUCTS
dbseek(whatever)
select INVOICES

Thats' why the dc_setrelation seemed so much slicker.

Anyway, Roger: I'd still lik to know what stupid thing I'm doing. I tried attaching the zip of a test prg/exe/dbf/cdx but had problems.

I uploaded it to our ftp site:

http://ftp.ezpos.com/setrelation.zip

In the meantime, I'll try Chris's suggestion.

thanks

Re: dc_setrelation problem

Posted: Thu Feb 24, 2011 11:23 am
by Cliff Wiernik
You will find out that also in Xbase++ programming, you generally should alias all function calls like DATABASE->(eof()) or similarly. Otherwise, sometimes the context has not fully switched when your code gets to that area and it could be in the wrong workarea. I had this problem with OrdSetfocus() just as one example when users switched screens and the workarea switch occurred slower than windows responded to the screen change.

Re: dc_setrelation problem

Posted: Thu Feb 24, 2011 12:13 pm
by rdonnay
Here's your problem. You were setting a relation to itself.

This is the correct code:

Code: Select all

dbselectarea('invoices')
dc_SetRelation("products", {||invoices->i_prodid} )

Re: dc_setrelation problem

Posted: Thu Feb 24, 2011 12:26 pm
by BruceN
Ahhh... knew it haad to be some stupid thing.

thanks