Subversion Repositories recyclebinunit

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
12 daniel-mar 1
unit Functions;
2
 
3
(*
4
    Some Delphi Functions
5
    by Daniel Marschall
6
*)
7
 
8
interface
9
 
10
uses
11
  SysUtils, Registry;
12
 
13
function RegistryReadDump(AReg: TRegistry; AName: string): string;
14
function BinaryStringToHexDump(ABinaryString: string): string;
15
 
16
type
17
  TNibble = $0..$F;
18
 
19
function LowerNibble(B: Byte): TNibble;
20
function UpperNibble(B: Byte): TNibble;
21
function MakeByte(UpperNibble, LowerNibble: TNibble): Byte;
22
 
23
type
24
  TBitPos = 0..7;
25
 
26
function GetBit(B: Byte; BitPos: TBitPos): boolean; overload;
27
function GetBit(B: Char; BitPos: TBitPos): boolean; overload;
28
 
29
implementation
30
 
31
function RegistryReadDump(AReg: TRegistry; AName: string): string;
32
const
33
  // Win2000 RegEdit has set the max input length of a REG_BINARY to $3FFF.
34
  // Probably its the longest possible binary string and not just a GUI limit.
35
  BufMax = $3FFF;
36
var
37
  buf: array[0..BufMax] of byte;
38
  i: integer;
39
  realsize: integer;
40
begin
41
  realsize := AReg.ReadBinaryData(AName, buf, SizeOf(buf));
42
 
43
  for i := 0 to realsize-1 do
44
  begin
45
    result := result + chr(buf[i]);
46
  end;
47
end;
48
 
49
function BinaryStringToHexDump(ABinaryString: string): string;
50
var
51
  i: integer;
52
begin
53
  for i := 1 to Length(ABinaryString) do
54
  begin
55
    result := result + IntToHex(Ord(ABinaryString[i]), 2);
56
    if i <> Length(ABinaryString) then
57
      result := result + ' ';
58
  end;
59
end;
60
 
61
function LowerNibble(B: Byte): TNibble;
62
begin
63
  result := B and 15 {00001111};
64
end;
65
 
66
function UpperNibble(B: Byte): TNibble;
67
begin
68
  result := B and 240 {11110000};
69
end;
70
 
71
function MakeByte(UpperNibble, LowerNibble: TNibble): Byte;
72
begin
73
  result := LowerNibble + UpperNibble * $10;
74
end;
75
 
76
function GetBit(B: Byte; BitPos: TBitPos): boolean;
77
var
78
  p: byte;
79
begin
80
  p := 1 shl BitPos; // 2 ^ BitPos
81
  result := B and p = p;
82
end;
83
 
84
function GetBit(B: Char; BitPos: TBitPos): boolean;
85
begin
86
  result := GetBit(Ord(B), BitPos);
87
end;
88
 
89
end.