Temporarily change filters

amadman114amadman114 Member Posts: 36
Hi, I would like to temporarily add a filter to a range of data, perform an operation, and then remove it.
Is this possible? If so, how?

Process workflow:

1. *Various filters are dynamically set and data is manipulated*

2. *Temporary filters are set to obtain a value*

3. *Previous filers are reset*

Comments

  • geordiegeordie Member Posts: 655
    Hi, you mean something like this?
    YourTable.SETRANGE("Posting Date",StarDate,EndDate);
    IF YourTable.FINDSET THEN
      REPEAT
        //Perform some operation
      UNTIL YourTable.NEXT = 0;
    
    YourTable.SETRANGE("Posting Date")
    
  • vaprogvaprog Member Posts: 1,141
    Assuming you don't know what filter are set nor on which filtergroup they are set, and you need to honor all of them, even the ones placed on fields you need to filter yourself, proceed like this:
    1. Save the current filtergroup.
    2. In a loop set a new filtergroup and check the filters set in that group using GETFILTERS until GETFILTERS returns an empty string
    3. Set your filters
    4. perform your operation
    5. clear your filters, one by one
    6. restore the original filtergroup
  • amadman114amadman114 Member Posts: 36
    Could someone give an example of this? I've never used filtergroups before and I'm a tad confused :cry:
  • geordiegeordie Member Posts: 655
    Vaprog's method is much more complete, according to him you can start from this code:
    //Save current filtergroups
    FOR i := 0 TO 255 DO BEGIN
      YourTable.FILTERGROUP(i);
      IF YourTable.GETFILTERS <> '' THEN
        OldFilterGroup := i;
    END;
    
    //Set first "free" filtergroup
    CLEAR(i);
    REPEAT
      YourTable.FILTERGROUP(i);
      i += 1;
    UNTIL YourTable.GETFILTERS = '';
    
    //Apply new filter
    YourTable.SETRANGE("Posting Date",StartDate,EndDate);
    
    //Perform some operation
    
    //Clear filter
    YourTable.SETRANGE("Posting Date");
    
    //Restore previous filtergroup
    YourTable.FILTERGROUP(OldFilterGroup);
    
  • vaprogvaprog Member Posts: 1,141
    Well, to get the current filtergroup you better do
    OldFilterGroup := YourTable.FILTERGROUP;
    

    To find an available filter group I would leave out the predefined filtergroups, especially filtergroup 1 as it has global scope.
    See FILTERGROUP Function (Record) on MSDN and for a more detailed explanation of the special filtergroup 1 KB 969590 (I hope MS fixed it's endless redirection loop by the time you try to view this ...).
Sign In or Register to comment.