0

I am using TAdvToolBarPager with many pages(AdvPage1, AdvPage2, AdvPage3...).Each page contains many edits,navigators,etc.. Based on the user right i would like to constraint properties, i.e for ADMIN i would like to show all the pages (1,2,3) but for USER i would like to show only page (1,2) or (1).

I am able to disable all edits,navigators using the code given below. Could some one help how i can set the pages in TAdvToolBarPager visble based on constraints/ Any other alternative way to achieve this. Thanks in advance!

Procedure SetForm(Form: TForm; enabled: Boolean);
var   PropInfo :  PPropInfo;
 i       :  Integer;
begin
  for i := 0 to Pred(Form.ComponentCount) do
  begin
   if (Form.Components[i] is TDBEdit) or (Form.Components[i] is DBNavigator) then
  begin
    PropInfo := GetPropInfo(Form.Components[i].ClassInfo, 'Enabled');
    if PropInfo <> nil then
        SetOrdProp(Form.Components[i], PropInfo, Ord(enabled));
    end;
  end;
end;   
kiran kumar
  • 153
  • 4
  • 12
  • 1
    Can't you just set the TabVisible property of page 3 to False? If you want the page to be visible but not selectable, you can set TabEnabled to False instead. – Uwe Raabe May 03 '17 at 06:10
  • Yes i could do it using the mentioned. How could i iterate and set TabVisible / TabEnabled to the AdvPage in TAdvToolBarPager ? Form.AdvToolBarPager1.AdvPages[1].TabVisible := False; Form.AdvToolBarPager1.AdvPages[2].TabVisible := False; Form.AdvToolBarPager1.AdvPages[1].TabVisible := False; But i would like to set dynamically. – kiran kumar May 03 '17 at 06:16
  • Can you explain what you mean with "set dynamically"? How would you call your SetForm procedure above? – Uwe Raabe May 03 '17 at 07:17
  • I use many forms in my application. Each form has a TAdvToolBarPager. Each TAdvToolBarPager has many pages inside it. Based on Admin/User i would like to display pages. So I would like to pass the form name and visible property(true/false) from my main form and control all the other forms in application dynamically. I call the above mentioned SetForm by passing the form name and if the user is admin then i pass the boolean value as true and if the user is normal user then i pass the boolean value as false – kiran kumar May 03 '17 at 07:44
  • Create a (virtual?) procedure to do it in each form, using user type as parameter? – Dsm May 03 '17 at 08:23
  • How do you decide which pages in each forms AdvToolBarPager have to be disabled? – Uwe Raabe May 03 '17 at 09:11
  • Dsm: I would like to do in the main form instead of doing it on each form @Uwe Raabe: Based on the user type, For example User: Page1 and Page2 should be displayed and For Admin: Page1,2,3 should be displayed – kiran kumar May 03 '17 at 09:18

1 Answers1

1

According to your comments to the question and assuming that the admin page is always the third one, this simplified procedure should do what you want:

Procedure SetForm(Form: TForm; enabled: Boolean);
var
  i: Integer;
begin
  for i := 0 to Form.ComponentCount - 1 do begin
    if (Form.Components[i] is TAdvToolBarPager) then begin
      TAdvToolBarPager(Form.Components[i]).AdvPages[2].TabVisible := enabled;
      Exit; //  probably only one AdvToolBarPager available
    end;
  end;
end;
Uwe Raabe
  • 45,288
  • 3
  • 82
  • 130
  • Thanks, Works almost. But fails if i want to show page 2, 3 for user and 1,2,3 for admin. – kiran kumar May 03 '17 at 09:59
  • It is fairly easy to adjust the code to that. It might get tricky when the admin page is different on each form. Hence my initial question. You need a common condition to decide which page has to be visible or not. As long as you don't articulate this condition completely we can only guess. – Uwe Raabe May 03 '17 at 10:04
  • I have passed an another parameter in the procedure to decide which page should be displayed. I am facing an another problem using this code. When i make the TAdvToolBarPager(Form.Components[i]).AdvPages[0].TabVisible := false. The page is not getting dispayed but contents inside the page are displayed – kiran kumar May 03 '17 at 10:44
  • You should make sure that this page is currently not the active page. Switch to another page before making it invisible. – Uwe Raabe May 03 '17 at 10:53
  • Yes it works with the work around that you have mentioned. But is there an alternative way because we are not actually sure which page i will not be showing – kiran kumar May 03 '17 at 11:16
  • How do you expect any code to disable a page when you don't know which page to disable? You can choose a random page which makes your program working correct in one of three cases. – Uwe Raabe May 03 '17 at 11:23
  • Thanks will try with a random page then – kiran kumar May 03 '17 at 11:25