Quer aprender Delphi for PHP?

Caros amigos delphianos, estão com dificuldades em encontrar um bom material sobre Delphi for PHP? Visite a Comunidade Delphi so PHP e veja algumas notícias sobre as novas tendências desta ferramenta. Lá você vai encontrar dicas, downloads, artigos, videos e muito mais sobre o Delphi for PHP. Para se cadastrar é muito simples, rápido e seguro. Clique aqui e seja o mais novo membro da Comunidade Delphi so PHP e bons estudos.

No mais até a próxima.


quarta-feira, 20 de maio de 2009

InputQuery com mascara de MaskEdit

Olá galera,

essa vai para os que conhecem o inputQuery... Vai uma dica maneira!

Veja na função abaixo como colocar o maskedit no InputQuery:

function InputQueryDef(const ACaption, APrompt: string;
var Value: String): Boolean;
var
Form: TForm;
Prompt: TLabel;
MaskEdit: TMaskEdit;
DialogUnits: TPoint;
ButtonTop, ButtonWidth, ButtonHeight: Integer;

function GetAveCharSize(Canvas: TCanvas): TPoint;
var
I: Integer;
Buffer: array[0..51] of Char;
begin
for I := 0 to 25 do Buffer[I] := Chr(I + Ord('A'));
for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
Result.X := Result.X div 52;
end;
begin
Result := False;
Form := TForm.Create(Application);
with Form do
try
Canvas.Font := Font;
DialogUnits := GetAveCharSize(Canvas);
BorderStyle := bsDialog;
Caption := ACaption;
ClientWidth := MulDiv(180, DialogUnits.X, 4);
Position := poScreenCenter;
Prompt := TLabel.Create(Form);
with Prompt do
begin
Parent := Form;
Caption := APrompt;
Left := MulDiv(8, DialogUnits.X, 4);
Top := MulDiv(8, DialogUnits.Y, 8);
Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);
WordWrap := True;
end;
MaskEdit := TMaskEdit.Create(Form);
with MaskEdit do
begin
Parent := Form;
Left := Prompt.Left;
Top := Prompt.Top + Prompt.Height + 5;
Width := MulDiv(164, DialogUnits.X, 4);
MaxLength := 255;
EditMask := '!99/99/0000;1;_';
Text := Value;
SelectAll;
end;
ButtonTop := MaskEdit.Top + MaskEdit.Height + 15;
ButtonWidth := MulDiv(50, DialogUnits.X, 4);
ButtonHeight := MulDiv(14, DialogUnits.Y, 8);
with TButton.Create(Form) do
begin
Parent := Form;
Caption := 'OK';
ModalResult := mrOk;
Default := True;
SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,
ButtonHeight);
end;
with TButton.Create(Form) do
begin
Parent := Form;
Caption := 'Cancelar';
ModalResult := mrCancel;
Cancel := True;
SetBounds(MulDiv(92, DialogUnits.X, 4), MaskEdit.Top + MaskEdit.Height + 15,
ButtonWidth, ButtonHeight);
Form.ClientHeight := Top + Height + 13;
end;
if ShowModal = mrOk then
begin
Value := MaskEdit.Text;
Result := True;
end;
finally
Form.Free;
end;
end;


Esta função não é nada mais nada menos que a propria função nativa do Delphi, só que rescrita com o MaskEdit!

Só isso...

Att,

Cadastro de senha mais segura!

Bem, vou mostrar agora uma função que obriga a senha possuir o primeiro caracter maiusculo e conter números.

Veja logo abaixo esta função:

function fValidaSenhaEspecial(const senha: string): boolean;
var
i, y: integer;
_s : string;
begin
// Inicia a função do falsa...
result := false;
// Verificando se a primeira letra é maiúscula.
if (pos(uppercase(copy(senha,1,1)),senha) = 1) then
for y := 1 to 9 do
for i := 1 to Length(senha) do
begin
_s := copy(senha,i,1);
// Verificando se há algum numero na string.
if (_s = inttostr(y)) then
// Todas validações foram feitas com sucesso.
result := true;
end;
end;


Simples não!?

Vamos ver agora como utiliza-la.

procedure Form1.Buttononclick(Sender: TObject);
begin
// Desta forma ele retorna FALSE
if (ValidaSenhaEspecial('elias10')) then
showmessage('Senha deve conter carecter o primeiro maiusculo e numeros!');

// Desta forma ele retorna TRUE
if (ValidaSenhaEspecial('Elias10')) then
showmessage('Senha OK!');
end;


Então pessoal, foi esta minha dica de hoje. Espero que ajude em algum lugar do seu código.

Att,

Parceria