Ver Mensaje Individual
  #6  
Antiguo 08-02-2007
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 26
seoane Va por buen camino
La explicacion esta en la implementacion de la clase TWinControl de la que desciende el TEdit. Cuando recibe el mensage WM_CHAR, se ejecuta lo siguiente:

Código Delphi [-]
function TWinControl.DoKeyPress(var Message: TWMKey): Boolean;
var
  Form: TCustomForm;
  Ch: Char;
begin
  Result := True;
  Form := GetParentForm(Self);
  if (Form <> nil) and (Form <> Self) and Form.KeyPreview and
    TWinControl(Form).DoKeyPress(Message) then Exit;
  if not (csNoStdEvents in ControlStyle) then
    with Message do
    begin
      Ch := Char(CharCode);
      KeyPress(Ch); // <-- Este es el evento OnKeyPress
      CharCode := Word(Ch);
      if Char(CharCode) = #0 then Exit;
    end;
  Result := False;
end;

procedure TWinControl.WMChar(var Message: TWMChar); // <- Esto maneja el mensaje WM_CHAR
begin
  if not DoKeyPress(Message) then inherited;
end;

Como ves, si no se pone el valor de key a cero, el resultado de la función DoKeyPress es FALSE, por lo que es delphi quien llama a inherited. Poniendo key a cero evitamos que eso pase.
Responder Con Cita