Board index » delphi » Tedit and ENTER-key

Tedit and ENTER-key

Hello all,

Sorry, I believe this has been asked here before.
When I am editing something in a TEdit box (runtime), I want to be able to  
press ENTER (and thus accept the input). The program only beeps at me when  
I press ENTER. The Forms KeyPreview is set to true.
Any hints ?

regards
Wolfgang Zehntner

## CrossPoint v3.1 ##

 

Re:Tedit and ENTER-key


In <5x5CF4BX...@woze.in-passau.de> zehnt...@woze.in-passau.de (Wolfgang
Quote
Zehntner) writes:

>Hello all,

>Sorry, I believe this has been asked here before.
>When I am editing something in a TEdit box (runtime), I want to be
able to  
>press ENTER (and thus accept the input). The program only beeps at me
when  
>I press ENTER. The Forms KeyPreview is set to true.
>Any hints ?

>regards
>Wolfgang Zehntner

>## CrossPoint v3.1 ##

private
 procedure wndproc (var message: tmessage);
 override;

implementation

{......................}

procedure toeform.wndproc(var message: tmessage);
begin
 if (activecontrol is tedit) and (twmkey(message).charcode = vk_return
then
begin
twmkey(message).charcode := vk_tab;
end;
inherited wndproc(message)
end;

Ben
Arrow

Re:Tedit and ENTER-key


Quote
zehnt...@woze.in-passau.de (Wolfgang Zehntner) wrote:
>Sorry, I believe this has been asked here before.
>When I am editing something in a TEdit box (runtime), I want to be able to  
>press ENTER (and thus accept the input). The program only beeps at me when  
>I press ENTER. The Forms KeyPreview is set to true.
>Any hints ?

Try the following

procedure TEnterForm.FormKeyPress(Sender: TObject; var Key: Char);
var
        done: Boolean;
  next: boolean;
  i: integer;
begin
        if Key = #13 then begin
        Key := #0;
        if (ActiveControl is TDBGrid) then begin
        with TDBGrid(ActiveControl) do begin
        done := False;
        next := False;
        i := selectedIndex;
        while not done do begin
                if selectedIndex < fieldcount -1 then
                selectedIndex := selectedIndex + 1
          else begin
                SelectedIndex := 0;
            next := True;
            end;
          done := not Fields[SelectedIndex].ReadOnly = True;
          if (not done) and (selectedIndex = i) then
                done := True;
          end;
        if next then begin
          TTable(DataSource.DataSet).Next;
          if TTable(DataSource.DataSet).eof then begin
                selectedIndex := 0;
                TTable(DataSource.DataSet).Append;
            end;
          end;
        end;
        end
    else
        Perform(WM_NEXTDLGCTL,0,0);
    end;
end;

It handles the problem very well.

Farley Carter
car...@idirect.com

Other Threads