Mascarar InPutBox
Como criar uma máscara no Edit do InputBox? Ou seja, se o usuário digitar na InputBox: Eu sou eu, deveria aparecer:*********. O q devo fazer? O mesmo q se eu colocasse a propriedade PASSWORDCHAR de um componente TEdit para * ou @ ou $ e etc..
Paulo
Curtidas 0
Respostas
Aroldo Zanela
02/08/2003
Paulo,
Contribuição do Fernando Allen:
Como essa nova função não faz parte do padrão da distribuição do delphi, o ideal seria copiar este código, colocálo em outra unit e sobrecarregar a função (cláusula overload) para manter o mesmo nome mas com parâmetros diferentes, não esquecendo de importar as Units necessárias na cláusula Uses, como a unit Mask, por exemplo
Contribuição do Fernando Allen:
Como essa nova função não faz parte do padrão da distribuição do delphi, o ideal seria copiar este código, colocálo em outra unit e sobrecarregar a função (cláusula overload) para manter o mesmo nome mas com parâmetros diferentes, não esquecendo de importar as Units necessárias na cláusula Uses, como a unit Mask, por exemplo
function InputQuery(const ACaption, APrompt: string; var Value: string; const AMask: String = ´´): Boolean; overload; var Form: TForm; Prompt: TLabel; Edit: TMaskEdit; // redefinir o componente Edit para TMaskEdit DialogUnits: TPoint; ButtonTop, ButtonWidth, ButtonHeight: Integer; 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); ClientHeight := MulDiv(63, DialogUnits.Y, 8); Position := poScreenCenter; Prompt := TLabel.Create(Form); with Prompt do begin Parent := Form; AutoSize := True; Left := MulDiv(8, DialogUnits.X, 4); Top := MulDiv(8, DialogUnits.Y, 8); Caption := APrompt; end; Edit := TMaskEdit.Create(Form); // Mudar p/ maskedit - OK with Edit do begin Parent := Form; Edit.EditMask := AMask; // Atribuir a máscara Left := Prompt.Left; Top := MulDiv(19, DialogUnits.Y, 8); Width := MulDiv(164, DialogUnits.X, 4); MaxLength := 255; Text := Value; SelectAll; end; ButtonTop := MulDiv(41, DialogUnits.Y, 8); ButtonWidth := MulDiv(50, DialogUnits.X, 4); ButtonHeight := MulDiv(14, DialogUnits.Y, 8); with TButton.Create(Form) do begin Parent := Form; Caption := SMsgDlgOK; ModalResult := mrOk; Default := True; SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth, ButtonHeight); end; with TButton.Create(Form) do begin Parent := Form; Caption := SMsgDlgCancel; ModalResult := mrCancel; Cancel := True; SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, ButtonWidth, ButtonHeight); end; if ShowModal = mrOk then begin Value := Edit.Text; Result := True; end; finally Form.Free; end; end;
GOSTEI 0