Ver Mensaje Individual
  #4  
Antiguo 06-12-2012
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
dvd2000,

Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, StdCtrls, DBCtrls, DB, ADODB, Mask;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    DBGrid1: TDBGrid;
    Memo1: TMemo;
    DBMemo1: TDBMemo;
    ADOConnection1: TADOConnection;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    DBEdit1: TDBEdit;
    procedure DBMemo1KeyPress(Sender: TObject; var Key: Char);
    procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
    procedure DBEdit1KeyPress(Sender: TObject; var Key: Char);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
    procedure Memo1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
   MaxLongComment = 30;

var
  Form1: TForm1;
  CountChar : Integer;

implementation

{$R *.dfm}

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
   if (Length(Edit1.Text) >= MaxLongComment) and (Key <> #8) then
   begin
      Key := #0;
      ShowMessage('Máxima longitud alcanzada');
   end
end;

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
   if (Length(Memo1.Text) >= MaxLongComment) and (Key <> #8) then
   begin
      Key := #0;
      ShowMessage('Máxima longitud alcanzada');
   end
end;

procedure TForm1.DBEdit1KeyPress(Sender: TObject; var Key: Char);
begin
   if (Length(DBEdit1.Text) >= MaxLongComment) and (Key <> #8) then
   begin
      Key := #0;
      ShowMessage('Máxima longitud alcanzada');
   end
end;

procedure TForm1.DBMemo1KeyPress(Sender: TObject; var Key: Char);
begin
   if (Length(DBMemo1.Text) >= MaxLongComment) and (Key <> #8) then
   begin
      Key := #0;
      ShowMessage('Máxima longitud alcanzada');
   end
end;

procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
   if DBGrid1.Fields[DBGrid1.SelectedIndex]=(DBGrid1.DataSource.DataSet.FieldByName('Author')) then
   begin
      if DBGrid1.Controls[0] is TInPlaceEdit then
      with DBGrid1.Controls[0] as TInPlaceEdit do
      begin
         if (GetTextLen >= MaxLongComment) and (Key <> #8) then
         begin
            Key := #0;
            ShowMessage('Máxima longitud alcanzada');
         end;
      end;
   end;
end;

end.
El código anterior muestra ejemplos de como controlar la longitud de un texto en un control de entrada.

Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 06-12-2012 a las 20:00:42.
Responder Con Cita