To the main page...The list of my products...Some texts...Sample applications, tips, tricks...If you need support...
 

 
ACL Editor
Step 3. Access mask editor

On this step we shall create a new form to allow access mask editing. As you remember the access mask is a set of 32 bits and each bit describes specific type of access. To be more accurate note that bits from 0 to 15 are used as a specific object access rights, bits 16-20 are used as common access rights. Some of other bits are reserved while other are used to get generic access rights. So our editor form will contain 20 checkboxes, checked box means that corresponding bit is set. There are nothing SvCom specific in this form so you can skip this step and continue with the next one.

Well, create a new form and place 20 checkboxes on it. Our example will be used to adjust file's security so captions of each bit reflect the access types for files. Not all of bits are used with files so some of checkboxes will be disabled. So the resulting form will look like image below (run-time)

In spite of large number of controls on this form the event handling will be simple enough. To reduce the code size set the Tag property for each checkbox: it should be 1 = 2^0 for the Bit 0, 2 = 2^1 for the Bit 1, 4 = 2^2 for the Bit 2 and so on. The Tag property for the last bit should be equal to 1048576=2^20. After that we can use one common handler for all checkboxes. To add it select all checkboxes and set the OnClick event handler. Set it`s name to CBxBitClick. The body of this handler should look like shown below:



 
 

 
 

 

 
 

procedure TFileAccessForm.CBxBitClick(Sender: TObject);
begin
    with Sender as TCheckBox do
    begin
        if Checked then
            _AccessMask:=_AccessMask or DWORD(Tag)
        else
            _AccessMask:=_AccessMask and not DWORD(Tag);
    end;
    LbMask.Caption:='$'+IntToHex(AccessMask,8);
end;

The _AccessMask is a variable that is stored in the form and holds the current access mask value. It is used to declare AccessMaks property for our form:


























 
 
 

 
 
 
 
 
 
 
 

type
  TFileAccessForm = class(TForm)
// Skipped
    procedure CBxBitClick(Sender: TObject);
  private
    { Private declarations }
    _AccessMask: DWORD;
    procedure SetAccessMask(Value: DWORD);
  public
    { Public declarations }
    property AccessMask: DWORD read _AccessMask write SetAccessMask;
  end;

var
  FileAccessForm: TFileAccessForm;

implementation

{$R *.DFM}

procedure TFileAccessForm.SetAccessMask(Value: DWORD);
var i: Integer;
    Ctl: TControl;
    CBx: TCheckBox;
begin
    _AccessMask:=0;
    for i:=0 to ControlCount-1 do
    begin
        Ctl:=Controls[i];
        if not (Ctl is TCheckBox) then continue;
        CBx:=Ctl as TCheckBox;
        CBx.Checked:=(CBx.Tag and Value) <> 0;
        if CBx.Checked then _AccessMask:=_AccessMask or DWORD(CBx.Tag);
    end;
    LbMask.Caption:='$'+IntToHex(AccessMask,8);
end;

As you see the Tag property is used to set checkboxes checked/unchecked state. It allows to set checkboxes in cycle instead of duplicating the same code for each control separately.

The final changes that we shall do is the AccessMaskText function. This function was used on the previous step to show readable access mask description and it is time to implement it:

























 
 
 

 
 
 
 
 
 
 
 
 
                      
type
  TFileAccessForm = class(TForm)
// Skipped
  public
    { Public declarations }
    property AccessMask: DWORD read _AccessMask write SetAccessMask;
    function AccessMaskText: String;
  end;

var
  FileAccessForm: TFileAccessForm;

implementation

{$R *.DFM}

//Skipped

function TFileAccessForm.AccessMaskText: String;
var i: Integer;
    Ctl: TControl;
    CBx: TCheckBox;
    S: String;
begin
    result:='';
    for i:=0 to ControlCount-1 do
    begin
        Ctl:=Controls[i];
        if not (Ctl is TCheckBox) then continue;
        CBx:=Ctl as TCheckBox;
        if not CBx.Checked then continue;
        S:=CBx.Caption;
        Delete(S,1,9);
        result:=result+S+'; ';
    end;
end;

Well, now you can test our application. After that only two steps remain in this example. With the first of them we shall implement the ACL editor itself and with the second we shall test it in different situations. Let's continue.

<< | Index | Step 1 | Step 2 | Step 3 | Step 4 | Step 5 | >>
Add your comment | Read comments


 
© 1998-2001 Alexey Dynnikov
My ICQ # is 18267212