Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Edit,comand button (https://www.clubdelphi.com/foros/showthread.php?t=34722)

mahlon 18-08-2006 19:10:06

Edit,comand button
 
necesito hacer varias cosas en un edit:

1. que solo acepte numeros (no letras).
2. que la aplicacion no falle al dejar el edit en blanco. (le doy a calcular y produce error).

--------------------------------------------------------------------------
ahora para un comand button:

que me funcionen cuando pulse la tecla Enter(todos los botones, claro).

--------------------------------------------------------------------------del cursor:

que se regrese al primer edit luego de que realize los calculos, y que baje en orden del primero al ultimo y luego a los botones del primero al ultimo.

--------------------------------------------------------------------------
necesito ejemplos de lo que es un case para no usar tanto if y si es posible algun curso de delphi 2006 for dummies ;)

cualquier sugerencia para programar es bienvenida
--------------------------------------------------------------------------

kman 18-08-2006 19:53:39

Saludos.
Empezando con todos tus problemas.

-Define primero que botón quieres que funcione con ENTER, cuando lo hagas cambia la propiedad DEFAULT a true (Todos en un mismo formulario no deberían de funcionar con enter).

Te recomiendo unas busquedas en el foro hay respuestas individuales a tus inquietudes.
Continuamos luego...

kman 18-08-2006 20:11:44

Realiza una condición para controlar el error de cálculo con edit en blanco, por ejemplo

Código Delphi [-]
If Trim(edit1.text)= '' then
//control de error aquí por ejemplo que tome valor cero, un mensaje o algo

kman 18-08-2006 20:13:42

En tu código, pon al final un edit.setfocus para que al finalizar el foco se coloque en el edit que deseas.

mahlon 19-08-2006 02:54:36

ok
 
gracias...


y para que solo pueda poner numeros en los edit?

vtdeleon 19-08-2006 03:19:36

Cita:

Empezado por mahlon
y para que solo pueda poner numeros en los edit?

Hiciste la busqeuda en el foro?

Saludos

MaMu 19-08-2006 09:22:21

Un TEdit limitado para entrar números Enteros

Código:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
 var sNumAnterior:string;
 begin
  sNumAnterior := (sender as TEdit).Text;
  if (key <> #3) and (key <> #22) then  // #3 = Copiar (Ctrl + C)
  begin                                // #22 = Pegar (Ctrl + V)
    if key = '-' then
    begin
      if ((pos(key,(sender as TEdit).Text) > 0) and
          (pos(key,(sender as TEdit).SelText) = 0))
          or
          ((sender as TEdit).SelStart > 0)
      then key:=#0;
    end
    else if not (key in ['0'..'9',#8]) then key:=#0;
  end;
  if key = #22 then
  try
    key := #0;
    (sender as TEdit).PasteFromClipBoard;
    StrToInt((sender as TEdit).Text);
  except
    (sender as TEdit).Text := sNumAnterior;
    (sender as TEdit).SelStart := Length((sender as TEdit).Text);
  end;
 end;


Un TEdit limitado para entrar números Reales

Código:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
 var sNumAnterior:string;
 begin
  sNumAnterior := (sender as TEdit).Text;
  if (key <> #3) and (key <> #22) then  // #3 = Copiar (Ctrl + C)
  begin                                // #22 = Pegar (Ctrl + V)
    if key in ['-','.'] then
    begin
      if (pos(key,(sender as TEdit).Text) > 0) and
          (pos(key,(sender as TEdit).SelText) = 0)
          then key:=#0;
      case key of
        '-': if ((sender as TEdit).SelStart > 0) then key:=#0;
        '.': if ((sender as TEdit).SelStart = 0) or
                (((sender as TEdit).SelStart = 1) and
                ((sender as TEdit).Text[1] = '-'))
              then key:=#0;
      end;
    end
    else if not (key in ['0'..'9',#8]) then key:=#0;
  end;
  if key = #22 then
  try
    key := #0;
    (sender as TEdit).PasteFromClipBoard;
    StrToFloat((sender as TEdit).Text);
  except
    (sender as TEdit).Text := sNumAnterior;
    (sender as TEdit).SelStart := Length((sender as TEdit).Text);
  end;
 end;

by Arturo_Ortí

arturo98@santandersupernet.com

kman 19-08-2006 20:12:58

Cita:

Empezado por mamu


Un TEdit limitado para entrar números Enteros


Un TEdit limitado para entrar números Reales

by Arturo_Ortí

Esas dos las quería yo también, cool!

kman 19-08-2006 20:17:59

Cita:

Empezado por mahlon
...y que baje en orden del primero al ultimo y luego a los botones del primero al ultimo.

A qué te refieres con esto? al Tab Order?
Si es aí En la Propiedad Taborder organiza tus objetos y usa este código para moverte entre ellos con la tecla + y -(Copia y pega el código en el evento Onkeypress de cada objeto):
Código Delphi [-]
If Key =#45 Then Begin
     keybd_event(16,0,0,0); // SHIFT oprimido
     keybd_event(9,0,0,0); // TAB oprimido
     Keybd_event(16,0,2,0); // Soltar el SHIFT  (NO SE PUEDE OMITIR)
     keybd_event(9,0,2,0); // TAB Released (Puede ser omitido)
     Key := #0
   end;
if key=#43 then begin
    keybd_event(9,0,0,0); // TAB oprimido
    keybd_event(9,0,2,0); // Soltar el Tab
    Key:=#0;
end;
Código Cortesía de un compañero que no recuerdo, pero todo crédito para él :)

mahlon 20-08-2006 04:00:35

busqueda
 
Cita:

Empezado por vtdeleon
Hiciste la busqeuda en el foro?

Saludos

no :):) :) :) :) :) :) :) :) :)

mahlon 20-08-2006 04:16:28

aclaracion
 
el segundo codigo incluye numeros como 0.5 ?






Cita:

Empezado por mamu
Un TEdit limitado para entrar números Enteros

Código:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
 var sNumAnterior:string;
 begin
  sNumAnterior := (sender as TEdit).Text;
  if (key <> #3) and (key <> #22) then  // #3 = Copiar (Ctrl + C)
  begin                                // #22 = Pegar (Ctrl + V)
    if key = '-' then
    begin
      if ((pos(key,(sender as TEdit).Text) > 0) and
          (pos(key,(sender as TEdit).SelText) = 0))
          or
          ((sender as TEdit).SelStart > 0)
      then key:=#0;
    end
    else if not (key in ['0'..'9',#8]) then key:=#0;
  end;
  if key = #22 then
  try
    key := #0;
    (sender as TEdit).PasteFromClipBoard;
    StrToInt((sender as TEdit).Text);
  except
    (sender as TEdit).Text := sNumAnterior;
    (sender as TEdit).SelStart := Length((sender as TEdit).Text);
  end;
 end;

Un TEdit limitado para entrar números Reales

Código:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
 var sNumAnterior:string;
 begin
  sNumAnterior := (sender as TEdit).Text;
  if (key <> #3) and (key <> #22) then  // #3 = Copiar (Ctrl + C)
  begin                                // #22 = Pegar (Ctrl + V)
    if key in ['-','.'] then
    begin
      if (pos(key,(sender as TEdit).Text) > 0) and
          (pos(key,(sender as TEdit).SelText) = 0)
          then key:=#0;
      case key of
        '-': if ((sender as TEdit).SelStart > 0) then key:=#0;
        '.': if ((sender as TEdit).SelStart = 0) or
                (((sender as TEdit).SelStart = 1) and
                ((sender as TEdit).Text[1] = '-'))
              then key:=#0;
      end;
    end
    else if not (key in ['0'..'9',#8]) then key:=#0;
  end;
  if key = #22 then
  try
    key := #0;
    (sender as TEdit).PasteFromClipBoard;
    StrToFloat((sender as TEdit).Text);
  except
    (sender as TEdit).Text := sNumAnterior;
    (sender as TEdit).SelStart := Length((sender as TEdit).Text);
  end;
 end;

by Arturo_Ortí

arturo98@santandersupernet.com


mahlon 20-08-2006 04:19:41

aclaracion para ti
 
me refiero a que el cursor tenga un order especifico dentro de todos los objetos.....





Cita:

Empezado por kman
A qué te refieres con esto? al Tab Order?
Si es aí En la Propiedad Taborder organiza tus objetos y usa este código para moverte entre ellos con la tecla + y -(Copia y pega el código en el evento Onkeypress de cada objeto):

Código Delphi [-]
If Key =#45 Then Begin
keybd_event(16,0,0,0); // SHIFT oprimido
keybd_event(9,0,0,0); // TAB oprimido
Keybd_event(16,0,2,0); // Soltar el SHIFT (NO SE PUEDE OMITIR)
keybd_event(9,0,2,0); // TAB Released (Puede ser omitido)
Key := #0
end;
if key=#43 then begin
keybd_event(9,0,0,0); // TAB oprimido
keybd_event(9,0,2,0); // Soltar el Tab
Key:=#0;
end;




Código Cortesía de un compañero que no recuerdo, pero todo crédito para él :)


MaMu 22-08-2006 08:07:23

Cita:

Empezado por mahlon
el segundo codigo incluye numeros como 0.5 ?

Exacto.

Saludos.

mahlon 28-08-2006 15:47:03

caracteres
 
Cita:

Empezado por mamu
Exacto.

Saludos.

gracias por el codigo!!!!!!!!!!!!!!!!:)

necesito algo parecido pero que solo acepte estos caracteres: desde la a hasta la z y A hasta la Z (mayusculas).

Saludos

Lepe 28-08-2006 16:13:30

Pues igual que con números:
Código Delphi [-]
if key in ['a'..'z', 'A'..'Z', 'ñ','Ñ'] then
  //  si se permite

Saludos

mahlon 28-08-2006 21:51:12

codigo
 
Cita:

Empezado por Lepe
Pues igual que con números:

Código Delphi [-]
if key in ['a'..'z', 'A'..'Z', 'ñ','Ñ'] then
// si se permite





Saludos

en ese caso es representado por matrices.
Saludos


La franja horaria es GMT +2. Ahora son las 11:22:23.

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