PDA

View Full Version : Question on Constraining



Joe Coley
28-Jan-2005, 11:26 AM
I am working with VDF 10.1 and have a dbgrid on a dbview. The view has a
"header" record, grid "child" records. When a "header" record is found, I
want to be able to constrain the "children" in two ways, first by the header
record, secondly by the value entered in a "form" on the dbview.

I have tried the following in the DD for Prodtots (without // of course):
//Procedure OnConstrain
// String sLocID
// Get LocID to sLocID
// Constrain Prodtots.Product_id eq Product.Product_id
// Constrain Prodtots.Location eq sLocID
//End_Procedure

It appears that by default the first constraint occurs. No matter what I
seem to do, as soon as I put the OnConstrain into the DD I then display no
child records.

I've tried creating a "button" and sending "rebuild_Constraints", but with
no luck.

Any help would be greatly appreciated. I thought that at one time I had
seen an example in the 9.1 help or examples, but I can't seem to find it
now.

TIA
Joe Coley

Knut Sparhell
28-Jan-2005, 12:13 PM
Joe Coley wrote:
> I am working with VDF 10.1 and have a dbgrid on a dbview. The view has a
> "header" record, grid "child" records. When a "header" record is found, I
> want to be able to constrain the "children" in two ways, first by the header
> record, secondly by the value entered in a "form" on the dbview.
>
> I have tried the following in the DD for Prodtots (without // of course):
> //Procedure OnConstrain
> // String sLocID
> // Get LocID to sLocID
> // Constrain Prodtots.Product_id eq Product.Product_id
> // Constrain Prodtots.Location eq sLocID
> //End_Procedure
>
> It appears that by default the first constraint occurs. No matter what I
> seem to do, as soon as I put the OnConstrain into the DD I then display no
> child records.

Is Prodtots.Product_id *related* to Product.Product_id?

If it is then there is no need for the

Constrain Prodtots.Product_id eq Product.Product_id

as this is implied by the Studio DDO-structure of Prodots_DD, by the

Set Constrain_file To Product.File_number

If you don't want this constrain to be in effect along with the second
constrain you must remove it by setting the Constrain_file to 0
somewhere, or remove the server DOO, and set it back on some condition.
The danger is that when activating a "child" that is not a *related*
child you will find a new header record. It seems unlikely to me that
this is what you want, so keep this.

Then try, assuming you will keep the relation constraint:

Property String LocID

Procedure OnConstrain
String sLocID
Get LocID To sLocID
If (sLocID>"") Constrain Prodtots.Location Eq sLocID
End_Procedure


In the view, at the oLocID_Form add

Procedure Exiting handle hoTo Returns Handle
String sValue
Get Value To sValue
Forward Get msg_Exiting hoTo To hoTo
Set LocID of Prodots_DD To sValue
Send Rebuild_constraints To Prodtots_DD
Send Beginning_of_data To oProdtots_Grid // or whatever name
Procedure_Return hoTo
End_Procedure

*or* this

Procedure OnChange
String sValue
If (Focus(Self)=Self) Begin
Get Value To sValue
Set LocId Of Prodots_DD To sValue
Send Rebuild_constraints To Prodtots_DD
End
End_Procedure
----------------------------------------------------------------

In case there is no relation in this case:

Sometimes an EQ constraint doesn't work, probably when the index of the
field is not unique. Then try

Constrain Prodtots.Product_id Between Product.Product_id ;
And Product.Product_id
If (sLocID>"") Constrain Prodtots.Location Eq sLocID


--
Knut Sparhell, Norway

starzen
30-Jan-2005, 08:18 AM
Joe

remove the constraint on product. You probably already have a relationship
for that constraint anyway.

So your code should be

Procedure OnConstrain
String sLocID
Get LocID to sLocID
Constrain Prodtots.Location eq sLocID
End_Procedure

in your refresh button do this

Procedure OnClick
Send Rebuild_Constraints TO prodtots_DD
Send Beginning_Of_Data TO myGrid // name of grid object
End_Procedure

if you do not have a relationship do this

Procedure OnConstrain
String sLocID sProdId

Get LocID to sLocID

Move product.product_id to sProdId

Constrain Prodtots.Product_id eq sProdId
Constrain Prodtots.Location eq sLocID
End_Procedure

in your refresh button do this

Procedure OnClick
... make sure product file is properly loaded in global buffer

Send Rebuild_Constraints TO prodtots_DD
Send Beginning_Of_Data TO myGrid // name of grid object
End_Procedure


--
Michael Salzlechner
StarZen Technologies, Inc
Visual DataFlex Controls, Tools and consulting
http://www.starzen.com