Mator

[xEdit] [Pascal] Test setting and printing flags

Sep 17th, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.31 KB | None | 0 0
  1. {
  2.   Description
  3. }
  4. unit userscript;
  5.  
  6. uses 'lib\mteFunctions';
  7.  
  8. procedure PrintFlags(flags: IInterface);
  9. begin
  10.   AddMessage(Format('%.3s', [GetEditValue(flags)]));
  11.   AddMessage(IntToHex(GetNativeValue(flags), 1));
  12. end;
  13.  
  14. procedure ToggleFlag(flags: IInterface; flag: Integer);
  15. var
  16.   flagValue: Integer;
  17. begin
  18.   flagValue := 1 shl flag;
  19.   if GetNativeValue(flags) and flagValue = 1 then
  20.     SetNativeValue(flags, GetNativeValue(flags) and not flagValue)
  21.   else
  22.     SetNativeValue(flags, GetNativeValue(flags) or flagValue);
  23. end;
  24.  
  25. procedure SetFlag(flags: IInterface; flag: Integer; state: boolean);
  26. var
  27.   flagValue: Integer;
  28. begin
  29.   flagValue := 1 shl flag;
  30.   if state then
  31.     SetNativeValue(flags, GetNativeValue(flags) or flagValue)
  32.   else
  33.     SetNativeValue(flags, GetNativeValue(flags) and not flagValue);
  34. end;
  35.  
  36. function Process(e: IInterface): integer;
  37. var
  38.   flags: IInterface;
  39. begin
  40.   flags := ElementByPath(e, 'DATA');
  41.   if not Assigned(flags) then
  42.     exit;
  43.   PrintFlags(flags);
  44.   //ToggleFlag(flags, 0);
  45.   SetFlag(flags, 0, false);
  46.   PrintFlags(flags);
  47.   SetFlag(flags, 1, true);
  48.   PrintFlags(flags);
  49.   SetFlag(flags, 2, true);
  50.   PrintFlags(flags);
  51.   SetFlag(flags, 0, false);
  52.   SetFlag(flags, 1, false);
  53.   SetFlag(flags, 2, false);
  54.   PrintFlags(flags);
  55.   Result := 0;
  56. end;
  57.  
  58. end.
Advertisement
Add Comment
Please, Sign In to add comment