Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Componente para signos ['+','-',' ']... (https://www.clubdelphi.com/foros/showthread.php?t=34310)

interested 04-08-2006 18:03:22

Componente para signos ['+','-',' ']...
 
Estimados Amigos gracias por sus Ayudas de antemano...

Como hago para crear un componente a partir de TEdit, donde pueda ingresar solamente un signo POSITIVO o NEGATIVO o UN ESPACIO EN BLANCO... por cierto solo un caracter;
EL PROBLEMA AQUI ES : QUE SE PUEDE INGRESAR CUALQUIER CANTIDAD DE SIGNOS... YO QUIERO SOLO UNO... Aqui tengo un avance...:

Código Delphi [-]
unit LeerSigno;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  Lsing = class(TEdit)
  private
    FConFocoColor: TColor;
    FSinFocoColor: TColor;
    procedure SetConFocoColor(Value: TColor);
    procedure SetSinFocoColor(Value: TColor);
    { Private declarations }
  protected
    procedure KeyPress(var Key: Char); override;
    procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
    procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
    { Protected declarations }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Public declarations }
  published
    property DelfinFocusColor: TColor read FConFocoColor write SetConFocoColor default clAqua;
    property DelfinNoFocusColor: TColor read FSinFocoColor write SetSinFocoColor default clWhite;
    { Published declarations }
  end;
procedure Register;
implementation
procedure Register;
begin
  RegisterComponents('INTERESTED', [Lsing]);
end;
constructor Lsing.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FConFocoColor := clAqua;
  FSinFocoColor := clWhite;
  Font.Name := 'Tahoma';
  Font.Size := 10;
  Font.Style := [fsBold];
  Height := 24;
  Width := 20;
end;
destructor Lsing.Destroy;
begin
  inherited Destroy;
end;
procedure Lsing.WMSetFocus(var Message: TWMSetFocus);
begin
  inherited;
  Color := FConFocoColor;
  Invalidate;
end;
procedure Lsing.WMKillFocus(var Message: TWMKillFocus);
begin
  inherited;
  Color := FSinFocoColor;
  SelStart := 0;
  Invalidate;
end;
procedure Lsing.SetConFocoColor(Value: TColor);
begin
  if FConFocoColor <> Value then
    begin
      FConFocoColor := Value;
      Invalidate;
    end;
end;
procedure Lsing.SetSinFocoColor(Value: TColor);
begin
  if FSinFocoColor <> Value then
    begin
      FSinFocoColor := Value;
      color := FSinFocoColor;
      Invalidate;
    end;
end;
procedure Lsing.KeyPress(var Key: Char);
begin
  if (key <> #3) and (key <> #22) then
    begin
      if not (key in ['+', '-', ' ', #8]) then
        key :=#0;
    end
  else
    key := #0;
  inherited KeyPress(Key);
end;
end.

AYUDA...:confused: por favor lo necesito Urge... :(

Bicho 04-08-2006 18:11:10

Hola, perdona que me meta, ero el Edit no tiene ya la propiedad MaxLenght??

Creo que no tienes que hacer nada al respecto, más que cambiar la propiedad maxlength a 1.

Alomejor no lo he entendido bien lo que pides.

Saludos


La franja horaria es GMT +2. Ahora son las 01:48:29.

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