Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > OOP
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 20-06-2014
Avatar de bulc
bulc bulc is offline
Miembro
 
Registrado: jun 2010
Posts: 415
Poder: 14
bulc Va por buen camino
Chequeo para InputBox...

He ideado este código para chequear la entrada en un InputBox. ¿Alguien sabe cómo ampliar el tamaño de letra de un InputBox?
Código Delphi [-]
procedure TForm5.Button1Click(Sender: TObject); //Valid for numbers
Var
  sDato: String;
  cChar: Char; // Exige System.Character en la cláusula USES
  I: Integer;
begin
sDato:='';
sDato:=InputBox('Introduce el número base...', 'Número:', sDato);
if sDato='' then EXIT;
For I:=0 to Length(sDato) do
begin
   cChar:=sDato[i];
    if  IsLetter(cChar) then
    begin  ShowMessage('Introduce un número, no letras...'); exit;  end;
end;
I:=StrToInt(sDato);
ShowMessage('Dato:  ' +  IntToStr( I));
end;
Responder Con Cita
  #2  
Antiguo 20-06-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola bulc.

Según entiendo, no podes cambiar el tamaño del font de un InputBox, pero nada impide hacerte una unidad con una función similar que sí lo permita.

Código Delphi [-]
(* 
  El siguiente código de ejemplo está basado en el original de Delphi (unit Dialogs.pas)  
*)
unit uMiMensaje;

interface

uses Windows, Graphics;

type
  TMiMensaje = class
  private
    FLabelFont, FEditFont: TFont;
    function GetAveCharSize(Canvas: TCanvas): TPoint;
    function InputQuery(const ACaption, APrompt: string;var Value: string): Boolean;
  public
    property LabelFont: TFont read FLabelFont write FLabelFont;
    property EditFont: TFont read FEditFont write FEditFont;
    constructor Create;
    function InputBox(const ACaption, APrompt, ADefault: string): string;
    destructor Destroy; override;
  end;

implementation

uses  SysUtils, CommDlg, Forms, Controls, StdCtrls;

constructor TMiMensaje.Create;
begin
  inherited Create;
  FLabelFont:= TFont.Create;
  FEditFont:= TFont.Create;
end;

function TMiMensaje.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;

function TMiMensaje.InputQuery(const ACaption, APrompt: string;var Value: string): Boolean;
const
  SMsgDlgOK = 'OK';
  SMsgDlgCancel = 'Cancel';
var
  Form: TForm;
  Prompt: TLabel;
  Edit: TEdit;
  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);
      Position := poScreenCenter;
      Prompt := TLabel.Create(Form);
      with Prompt do
      begin
        Parent := Form;
        Font.Assign(FLabelFont);
        Caption := APrompt;
        Left := MulDiv(8, DialogUnits.X, 4);
        Top := MulDiv(8, DialogUnits.Y, 8);
        Constraints.MaxWidth := MulDiv(164, DialogUnits.X, 4);
        WordWrap := True;
      end;
      Edit := TEdit.Create(Form);
      with Edit do
      begin
        Parent := Form;
        Font.Assign(FEditFont);
        Left := Prompt.Left;
        Top := Prompt.Top + Prompt.Height + 5;
        Width := MulDiv(164, DialogUnits.X, 4);
        MaxLength := 255;
        Text := Value;
        SelectAll;
      end;
      ButtonTop := Edit.Top + Edit.Height + 15;
      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), Edit.Top + Edit.Height + 15,
          ButtonWidth, ButtonHeight);
        Form.ClientHeight := Top + Height + 13;
      end;
      if ShowModal = mrOk then
      begin
        Value := Edit.Text;
        Result := True;
      end;
    finally
      Form.Free;
    end;
end;

function TMiMensaje.InputBox(const ACaption, APrompt, ADefault: string): string;
begin
  Result := ADefault;
  InputQuery(ACaption, APrompt, Result);
end;

destructor TMiMensaje.Destroy;
begin
  FLabelFont.Free;
  FEditFont.Free;
  inherited;
end;

end.

Ejemplo de uso:
Código Delphi [-]
...
implementation

uses uMiMensaje;

procedure TForm1.Button1Click(Sender: TObject);
var
  sDato: string;
begin
  with TMiMensaje.Create do
  try
    LabelFont.Size:= 14;
    LabelFont.Name:= 'Segoe Script';
    EditFont.Size:= 9;
    EditFont.Name:= 'Segoe Print';
    sDato:= InputBox('Introduce el número base...', 'Número:', sDato);
    ShowMessage(sDato);
  finally
    Free;
  end;
end;

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
InputBox e InputQuery olbeup Varios 5 17-05-2013 09:16:36
ayuda con inputbox! gabriel2000 Varios 5 20-05-2011 06:03:09
Calcular un digito de chequeo GrupoDatasoft Varios 7 09-02-2009 17:53:53
inputbox ????? douglas OOP 1 24-10-2007 07:00:33
InputBox fmtidona Varios 2 16-10-2006 19:52:32


La franja horaria es GMT +2. Ahora son las 18:29:05.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi