Howardpc, see:
First call:
procedure TFrmAcesso.AIProtect;
begin
randomize;
codabert:=GeraChave(afn,nat,random(6)+7);
Caption:=' ('+codabert+') '+Caption;
end;
undcentral.pas
unit undcentral;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, ExtCtrls, Forms, undtipos, StrHolder, StrUtils, Dialogs;
type
{ TCentral }
TCentral = class(TDataModule)
SthCofre0: TStrHolder;
SthCofre1: TStrHolder;
SthCofre2: TStrHolder;
function PegaStr(const c:integer; const p:integer):string;
{...}
protected
{...}
end;
const
{...}
var
Central: TCentral;
{...}
function GeraChave(const b:TBase; const c:TCase; t:SmallInt):string;
implementation
uses
undacesso, undprincipal;
{function SortTChave:integer;
begin
result:=random((sec_tmaxc-sec_tminc))+sec_tminc+1;
end;}
function GeraChave(const b:TBase; const c:TCase; t:SmallInt):string; //Gera uma string aleatória com a base, tamanho e case informados
var
e: string; //Caracteres da base escolhida
x: integer; //Marcador de posição para estrutura de repetição, tamanho da chave
s: string=''; //Saída antes de ser tratada
begin
with Central do begin
case b of
bin: e:=PegaStr(1,0);
oct: e:=PegaStr(1,1);
dec: e:=PegaStr(1,2);
duo: e:=PegaStr(1,3);
hex: e:=PegaStr(1,4);
abc: e:=PegaStr(1,5);
afn: e:=PegaStr(1,6);
end;
end;
case t of
0: t:=SortTChave;
else if (not t>0)
then t:=1;
end;
for x:=0 to t-1 do begin
s:=s+e[random(Length(e))+1];
end;
case c of
mai: s:=UpperCase(s);
min: s:=LowerCase(s);
end;
result:=s;
end;
function TCentral.PegaStr(const c:integer; const p:integer):string;
begin
// result:=GeraChave(afn,nat,0);
case c of
0: result:=SthCofre0.Strings.Strings[p];
1: result:=SthCofre1.Strings.Strings[p];
2: result:=SthCofre2.Strings.Strings[p];
end;
end;
{...}
{$R *.lfm}
end.
undtipos.pas
unit undtipos;
{$mode objfpc}{$H+}
interface
uses
Classes, dbf, FileUtil, SysUtils;
type
TEixo=(ex,ey,ez);
TBase=(bin,oct,dec,duo,hex,abc,afn);
{...}
TCase=(mai,min,nat);
{...}
implementation
uses
undcentral;
{...}
end.