Link to home
Start Free TrialLog in
Avatar of firekiller15
firekiller15

asked on

why if i use TAB key on the keyboard to select save button it will become enabled

delphi
why if i use TAB key on the keyboard to select save button it will become enabled
tab.bmp
Avatar of MerijnB
MerijnB
Flag of Netherlands image

do you have any code in the OnExit event of the Edit, or in the UpdateActions event of the form?
Show some code.
in your previous post you have this code:

procedure TForm1.nameKeyUp(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  if (name.text = '') then
    Save.enabled := false
  else
    Save.enabled := true;
end;


this is what does it ...
is it standard TButton?
normally when Button.Enabled := False;
button shouldn't react to TAB (behaves like TabStop := False)

ziolko.
Avatar of firekiller15
firekiller15

ASKER

below is my code
whenever i use tab it will automatically enable save
##dfm##
object Form2: TForm2
  Left = 0
  Top = 0
  Width = 421
  Height = 201
  Caption = 'Form2'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Edit1: TEdit
    Left = 152
    Top = 16
    Width = 121
    Height = 21
    TabOrder = 0
    OnKeyUp = Edit1KeyUp
  end
  object Edit2: TEdit
    Left = 152
    Top = 40
    Width = 121
    Height = 21
    TabOrder = 1
    OnKeyUp = Edit1KeyUp
  end
  object Button1: TButton
    Left = 120
    Top = 64
    Width = 75
    Height = 25
    Caption = 'reset'
    TabOrder = 2
  end
  object Button2: TButton
    Left = 208
    Top = 64
    Width = 75
    Height = 25
    Caption = 'save'
    Enabled = False
    TabOrder = 3
    OnClick = Button2Click
  end
  object Button3: TButton
    Left = 296
    Top = 64
    Width = 75
    Height = 25
    Caption = 'cancel'
    TabOrder = 4
    OnClick = Button3Click
  end
end
 
##form##
unit Unit2;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
 
type
  TForm2 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button2Click(Sender: TObject);
    procedure Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
 
var
  Form2: TForm2;
 
implementation
 
{$R *.dfm}
 
procedure TForm2.Button3Click(Sender: TObject);
begin
close;
end;
 
procedure TForm2.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Edit1.text = '') then
    button2.enabled := false
  else
    button2.enabled := true;
end;
 
procedure TForm2.Button2Click(Sender: TObject);
begin
  button2.Enabled := False;
  showmessage('save');
  button1.Enabled := True;
end;
 
end.

Open in new window

yes, that's how you programmed it to behave ...

what are you trying to accomplish ?

try

procedure TForm2.Edit1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
{if (Edit1.text = '') then
    button2.enabled := false
  else
    button2.enabled := true; }
end;

procedure TForm2.Edit1Change(Sender: TObject);
begin
if (Edit1.text = '') then
    button2.enabled := false
  else
    button2.enabled := true;
end;
is the behaviour you want the following ?

the form opens and the data is displayed.
After the data has changed, the save button becomes active
After saving the Save button is disabled ?

ASKER CERTIFIED SOLUTION
Avatar of rfwoolf
rfwoolf
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial