-
Notifications
You must be signed in to change notification settings - Fork 16
Custom Functions
Matchers in model files can resolve functions. There are built-in functions but you can expand functionality by adding your own custom functions to suit your needs.
Create a .pas file and store it in \SourceCode\Common\Functions folder
The file should define a function with the following signature:
function newFunc (const aArgs: array of string): Boolean;
where:
- newFunc: the name of the function
- aArgs: the arguments that need to be passed. They are defined as dynamic array
- result: the function should return a true/false value to indicate whether the "new functionality" is resolved successfully or not
Once the function is created, you need to let Casbin4D know the file exists and, consequently, to load it. Uncomment (or add) and include directive {$I}
in this location in Casbin.Functions.pas
Then, you have to register it in the internal dictionary in and in particularly in loadCustomFunctions as follows:
procedure TFunctions.loadCustomFunctions;
begin
...
fDictionary.Add('FuncName', newFunc);
...
end;
Make sure you write tests for your new function. If you want to share it with others, you should add Tests in the Test files
Now you can use the function in a model file by referring to it using the FuncName from loadCustomFunctions