Home RAP
New Blog Posts: Merging Reports - Part 1 and Part 2

Bit operations in RAP?

Hi Team,
I use a 32bit integer to hold security info. Each bit represents a Users access to a function, or not.
I want to generate a report that shows what accesses each user has.
To do this I need to be able to test each bit of the integer and return something I can represent on a report.
I can't see any bit type operations in RAP.
Is there some way this can be done please?
Regards & TIA,
Ian

Comments

  • Hi Ian,

    RAP does not natively support bitwise operations. This is something we will consider adding to a later release of the product.

    Currently you can easily create a pass-thru function to perform these calculations.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Hi Nico,
    Thanks for that. Can you point me at an example of a pass-thru function pls.
    Regards,
    Ian
  • Hi Ian,

    RAP passthru examples can be found in the main RAP demo located in the \Demos\0. RAP\1. Main\ directory. See the following article on where these examples are installed on your machine.

    http://rbwiki.digital-metaphors.com/general/installation/tech-tip-demo-location/

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Hi Nico,
    I am getting there but is something I am missing.
    The following is my basic code for the function..
    {code}
    unit myRapFuncs0037;
    interface
    uses
    SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms, Dialogs, raFunc, ppRTTI;

    type
    TmyBitSetFunction = class (TraIntFunction)
    public
    procedure ExecuteFunction(aParams: TraParamList); override;
    class function GetSignature: String; override;
    end;

    implementation
    {------------------------------------------------------------------------------}
    { TmyBitSetFunction.GetSignature }

    class function TmyBitSetFunction.GetSignature: String;
    begin
    Result := 'function BitSet(const Value: Cardinal; const Bit: Byte): Boolean;';
    end; {class function, GetSignature}
    {------------------------------------------------------------------------------}
    { TmyBitSetFunction.ExecuteFunction }
    procedure TmyBitSetFunction.ExecuteFunction(aParams: TraParamList);
    var
    lbResult: Boolean;
    iValue, iBit: Integer;
    begin
    GetParamValue(0, iValue);
    GetParamValue(1, iBit);
    lbResult := (iValue and (1 shl iBit)) <> 0;
    SetParamValue(1, lbResult);
    end; {procedure, ExecuteFunction}
    initialization
    raRegisterFunction('BitSet', TmyBitSetFunction);
    finalization
    raUnRegisterFunction('BitSet');
    end.
    {code}
    This is based on example 31.
    It compiles OK and it seems to get into RAP but when I go to the Variable and select Language I get the following error.. "Cannot compile signature for Math function BitSet."
    I am suspecting it may be related to "TmyBitSetFunction = class (TraIntFunction)" but I am unsure.
    Can you advise please?

    Regards & TIA,
    Ian
  • Hi Ian,

    Your code looks good! I can see only a couple issues.

    1. RAP does not support unsigned types such as Cardinal or Byte. For the purposes of this routine, you will need to declare each parameter as an Integer then possibly check for compatibility in your ExecuteFunction call.

    class function TmyBitSetFunction.GetSignature: String;
    begin
    Result := 'function BitSet(const Value: Integer; const Bit: Integer): Boolean;';
    end; {class function, GetSignature}

    procedure TmyBitSetFunction.ExecuteFunction(aParams: TraParamList);
    var
    lbResult: Boolean;
    iValue, iBit: Integer;
    begin

    GetParamValue(0, iValue);
    GetParamValue(1, iBit);

    Result := False;

    if (iValue < 0) or (iBit < 0) or (iBit > 255) then exit; //or something similar
    ...


    2. Since there are 2 parameters in your function, the result value should be placed into the third parameter. So for your SetParamValue call, you will want to update parameter 2.

    Parameter 0: Value
    Parameter 1: Bit
    Parameter 2: Result

    SetParamValue(2, lbResult);




    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • Ah Ha! Excellent thanks Nico.

    Done. Works exactly as required.

    Many Thanks,
    Ian
Sign In or Register to comment.