/
YakuninAV
/
Convertors
Обзор
Документация
Войти
/
YakuninAV
/
Convertors
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Program Design/Delphi2007/BMasks.pas
204 строки
4 KB
YakuninAV
begin with gitflick
31 июл 2026, 15:21
31 июл 2026, 15:21
1dc0fc6
Код
Авторство
О чём код?
unit BMasks; interface uses SysUtils,ComUnit,Obj,Classes, Forms, ToolForm; const Digits = ['0'..'9']; Letters = ['�'..'�','�'..'�','a'..'z','A'..'Z']; type TMultiMask= class(TAsciizCollector) constructor Create(const AMaskStr: string); function IsValid(const C: string): boolean; function Get_MaskStr: string; procedure AddMask(const AMask: string); end; TNewMaskDlg = class(TToolForm1) private FNewMask: String; public constructor Create(AOwner: TComponent; const NonmaskedCypher: String); property NewMask: String read FNewMask; end; function EnterNewMask(const NonmaskedCypher: String): String; function MatchesCypherToMask(const Cypher, Mask: String): Boolean; implementation uses Buttons, StdCtrls, Controls, Graphics; function MatchesCypherToMask(const Cypher, Mask: String): Boolean; var i, im, ic, LM, LC: Integer; S, M: String; begin Result := False; M := Mask; DeleteSpaces(M); LM := Length(M); if LM = 0 then Exit; S := Cypher; DeleteSpaces(S); LC := Length(S); if LC = 0 then begin Result := True; Exit; end; im := 1; ic := 1; while im <= LM do begin case M[im] of '%': if (ic <= LC) and (S[ic] in Digits) then while (ic <= LC) and (S[ic] in Digits) do Inc(ic) else Exit; '&': if (ic <= LC) and (S[ic] in Letters) then while (ic <= LC) and (S[ic] in Letters) do Inc(ic) else Exit; '#': if (ic <= LC) and (S[ic] in Digits) then Inc(ic) else Exit; '@': if (ic <= LC) and (S[ic] in Letters) then Inc(ic) else Exit; else if (ic <= LC) and (AnsiCompareText(M[im], S[ic]) = 0) then Inc(ic) else Exit; end; if (im = LM) and (ic <> LC+1) then Exit; Inc(im); end; Result := True; { if Mask[im] = '%' then begin if (ic <= LC) and (S[ic] in Digits) then while S[ic] in Digits do Inc(ic) else Exit; if (im = LM) and (ic <> LC+1) then Exit; end else if Mask[im] = '&' then begin if (ic <= LC) and (S[ic] in Letters) then while S[ic] in Letters do Inc(ic) else Exit; if (im = LM) and (ic <> LC+1) then Exit; end else begin if AnsiUpperCase(Mask[im]) <> AnsiUpperCase(S[ic]) then Exit; Inc(ic); if (im = LM) and (ic <> LC+1) then Exit; end; Inc(im); end; Result := True; } end; { TMultiMask } procedure TMultiMask.AddMask(const AMask: string); var S: string; begin S:=AMask; DeleteSpaces(S); Add(StrNew(PChar(S))); end; constructor TMultiMask.Create(const AMaskStr: string); var S: string; A: TAsciizCollector; i: integer; begin S:=AMaskStr; DeleteSpaces(S); inherited Create(8); A:=StrDistribution(PChar(S),'#'); for i:=0 to A.Count-1 do Add(StrNew(A.At(i))); A.Free; end; function TMultiMask.Get_MaskStr: string; begin Result:=TotString('#'); end; function TMultiMask.IsValid(const C: string): boolean; var i: integer; begin Result:=false; i:=0; while not(Result) and (i<Count) do begin Result:=MatchesCypherToMask(C,string(At(i))); inc(i); end; end; { TNewMaskDlg } constructor TNewMaskDlg.Create(AOwner: TComponent; const NonmaskedCypher: String); var L: TLabel; E: TEdit; B: TBitBtn; begin inherited Create(AOwner); Width := 300; Height := 100; Caption := 'New Mask'; Position := poScreenCenter; BorderStyle := bsSizeable; BorderIcons := [biSystemMenu]; AutoScroll := False; L := TLabel.Create(Self); L.Parent := Self; L.Left := 8; L.Top := 10; L.Caption := '�����:'; E := TEdit.Create(Self); E.Parent := Self; E.Left := L.Left + L.Width + 5; E.Top := 6; E.Width := ClientWidth - E.Left - 8; E.Text := NonmaskedCypher; { L := TLabel.Create(Self); L.Parent := Self; L.Left := 8; L.Top := E.Top + E.Height + 7; L.Font.Style := [fsBold]; L.Caption := NonmaskedCypher; } B := TBitBtn.Create(Self); B.Parent := Self; B.Left := (ClientWidth - B.Width) div 2; B.Top := E.Top + E.Height + 5; B.Kind := bkOK; B.ModalResult := mrOK; B.Style := bsAutoDetect; ShowModal; if ModalResult = mrOK then FNewMask := E.Text else FNewMask := ''; end; function EnterNewMask(const NonmaskedCypher: String): String; var NMDlg: TNewMaskDlg; begin NMDlg := TNewMaskDlg.Create(nil, NonmaskedCypher); Result := NMDlg.NewMask; NMDlg.Free; end; end.