routines.inc

Exported from Notepad++
Function GetBufferSizeValue(I: Integer) : Integer; begin // Берем множитель и у множаем на 320, что бы было кратно размеру буфера модема // Еденица множителя = 0.01 секунде задержки (I:=100 - одна секунда, размер буфера - 32000 байт) { 2560 bites, 0,08 sec voice delay 3840 bites, 0,12 sec voice delay 5120 bites, 0,16 sec voice delay 7680 bites, 0,24 sec voice delay 10240 bites, 0,32 sec voice delay } if (I > 0) and (I <= 100) then Result := 320 * I else Result := 10240; end; function StrNormalize(var Input: string; EArray: string; Action: Integer): string; begin case Action of 1: begin while length(Input) <> 0 do begin if pos(Input[1], EArray) = 0 then delete(Input, 1, 1) else begin result := result + Input[1]; delete(Input, 1, 1); end; end; end; 2: begin while length(Input) <> 0 do begin if pos(Input[1], EArray) <> 0 then delete(Input, 1, 1) else begin result := result + Input[1]; delete(Input, 1, 1); end; end; end; else messagebox(0, 'Не корректный вызов функции.', '', mb_ok); end; end; function WordCount(CText: string): Longint; function Seps(As_Arg: Char): Boolean; begin Seps := As_Arg in // [#0..#$1F, ' ', '.', ',', '?', ':', ';', '(', ')', '/', '\']; [' ', ';', ',']; end; var Ix: Word; Work_Count: Longint; begin Work_Count := 0; Ix := 1; while Ix <= length(CText) do begin while (Ix <= length(CText)) and (Seps(CText[Ix])) do Inc(Ix); if Ix <= length(CText) then begin Inc(Work_Count); while (Ix <= length(CText)) and (not Seps(CText[Ix])) do Inc(Ix); end; end; WordCount := Work_Count; end; function GetToken(aString, SepChar: string; TokenNum: Byte): string; var Token: string; StrLen: Byte; TNum: Byte; TEnd: Byte; begin StrLen := length(aString); TNum := 1; TEnd := StrLen; while ((TNum <= TokenNum) and (TEnd <> 0)) do begin TEnd := pos(SepChar, aString); if TEnd <> 0 then begin Token := Copy(aString, 1, TEnd - 1); delete(aString, 1, TEnd); Inc(TNum); end else begin Token := aString; end; end; if TNum >= TokenNum then begin GetToken := Token; end else begin GetToken := ''; end; end; Function PhoneNumberisAllowed(PhoneNumber: String; Codes: String; MinL, MaxL: Integer; Var Answer: String): Boolean; { The functin returns True if PhoneNumber in range of MinLength and MaxLength, also in range of mask } Var X: Integer; Begin Result := False; If not(length(PhoneNumber) >= MinL) then Answer := 'Length of the number is shorter than allowed' else If not(length(PhoneNumber) <= MaxL) then Answer := 'Length of the number is longer than allowed' else If WordCount(Codes) > 0 then For X := 1 to WordCount(Codes) do begin Result := (Copy(PhoneNumber, 1, length(GetToken(Codes, ',', X))) = GetToken(Codes, ',', X)); If Result then Exit else Answer := 'The code of the number is not in list of allowed codes - ' + Codes; end else Result := True; End; function isAdmin(UserName:String; List : TListBox) : Boolean; var x : Integer; begin Result := False; if List.Items.Count > 0 then for x := 0 to List.Items.Count - 1 do if UserName = List.Items.Strings[x] then Result := True; end; procedure DeleteDuplicates(inlst: TListBox); var lst: TStringList; begin lst := TStringList.Create; try lst.Duplicates := dupIgnore; lst.Sorted := True; lst.Assign(inlst.Items); inlst.Items.Assign(lst); finally lst.free end; end; function StrPart(ABegin, AEnd, Str: String): String; var b, c: Integer; s: String; begin Result := '0'; if ABegin <> '' then b := pos(ABegin, Str) + length(ABegin) else b := 1; s := copy(Str, b, length(Str) - b + 1); if AEnd <> '' then begin c := pos(AEnd, s); Result := copy(Str, b , c-1); end else Result := s; end; function UCSToAnsi(AStr: AnsiString): AnsiString; function Convert(ACnvStr: AnsiString): AnsiChar; var j: integer; begin j := StrToIntDef('$'+ACnvStr, 0); case j of 1040..1103: j := j - 848; 1105: j := 184; end; Result := AnsiChar(j); end; var c, i: integer; begin Result := ''; c := Length(AStr) div 4; for i := 0 to c - 1 do Result := Result + Convert(Copy(AStr, i*4+1, 4)); end; function AnsiToUCS(AStr: AnsiString): AnsiString; function Convert(AChar: AnsiChar): AnsiString; var j: integer; begin Result := ''; j := ord(AChar); case j of 192..255: j := j + 848; 184: j := 1105; end; Result := IntToHex(j, 4) end; var c, i: integer; begin Result := ''; c := Length(AStr); for i := 1 to c do Result := Result + Convert(AStr[i]); end; function GetSpecialFolderPath(folder : integer) : string; const SHGFP_TYPE_CURRENT = 0; var path: array [0..MAX_PATH] of char; begin if SUCCEEDED(SHGetFolderPath(0,folder,0,SHGFP_TYPE_CURRENT,@path[0])) then Result := path else Result := ''; end;