Bonjour,

J'ai des problèmes avec la touche "tabulation avant" quand j'utilise la protection/déprotection des champs qui suivent (Enabled à False ou True).

J'utilise une forme de test, avec respectivement les champs suivants :
- ComboBox1 (Style = csDropDown)
- Edit1,
- Edit2,
- ComboBox2 (Style = csDropDown).

Traitement dans ComboBox1Exit :
Si ComboBox1.Text est saisi :
Edit1.Enabled := True;
Edit2.Enabled := True;
sinon (ComboBox1.Text non saisi = '')
Edit1.Enabled := False;
Edit2.Enabled := False;

Edit1.Enabled et Edit2.Enabled sont au départ initialisés à False.
Quand je sors de ComboBox1Exit après saisie, par la touche "tabulation avant", le curseur se positionne sur ComboBox2, il devrait logiquement se positionner sur Edit1. Pourtant Edit1 et Edit2 sont bien accessibles avec le curseur.
Quelqu'un aurait-il une idée : comment faire pour que le curseur se positionne sur Edit1 en sortant de ComboBox1 par la touche "tabulation avant" ?

Merci d'avance pour votre aide.

Source "test.pas" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
unit Test;
 
interface
 
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
 
type
  TFrmTest = class(TForm)
    ComboBox1: TComboBox;
    ListBox1: TListBox;
    Button1: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    ComboBox2: TComboBox;
    procedure FormShow(Sender: TObject);
    procedure ComboBox1Exit(Sender: TObject);
  private
    { Déclarations privées }
  public
    { Déclarations publiques }
  end;
 
var
  FrmTest: TFrmTest;
 
implementation
 
{$R *.dfm}
//---------------------------------------------------------------------------------------------------------------------------------------------------------
procedure TFrmTest.FormShow(Sender: TObject);
begin
  ComboBox1.Clear;
  ComboBox1.Items.Insert(ComboBox1.Items.Count, 'a');
  ComboBox1.Items.Insert(ComboBox1.Items.Count, 'b');
  ComboBox2.Clear;
  ComboBox2.Items.Insert(ComboBox2.Items.Count, 'c');
  ComboBox2.Items.Insert(ComboBox2.Items.Count, 'd');
  ComboBox2.Items.Insert(ComboBox2.Items.Count, 'e');
  Edit1.Text    := '';
  Edit2.Text    := '';
  Edit1.Enabled := false;
  Edit2.Enabled := false;
end;
//---------------------------------------------------------------------------------------------------------------------------------------------------------
procedure TFrmTest.ComboBox1Exit(Sender: TObject);
begin
  if (ComboBox1.Text <> '') then
    begin
      Edit1.Enabled := true;
      Edit2.Enabled := true;
    end
  else
    begin
      Edit1.Enabled := false;
      Edit2.Enabled := false;
    end;
end;
//----------------------------------------------------------------------------------------------------------------------------------------------------
end.
Source "test.dfm" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
object FrmTest: TFrmTest
  Left = 390
  Top = 168
  Width = 393
  Height = 219
  Caption = 'FrmTest'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object ComboBox1: TComboBox
    Left = 8
    Top = 24
    Width = 353
    Height = 21
    AutoComplete = False
    ItemHeight = 13
    TabOrder = 0
    Text = 'ComboBox1'
    OnExit = ComboBox1Exit
  end
  object Edit1: TEdit
    Left = 8
    Top = 64
    Width = 121
    Height = 21
    TabOrder = 1
    Text = 'Edit1'
  end
  object Edit2: TEdit
    Left = 8
    Top = 104
    Width = 121
    Height = 21
    TabOrder = 2
    Text = 'Edit2'
  end
  object ComboBox2: TComboBox
    Left = 8
    Top = 144
    Width = 353
    Height = 21
    ItemHeight = 13
    TabOrder = 3
    Text = 'ComboBox2'
  end
end
Source "TestsDelphi.dpr" :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
program TestsDelphi;
 
uses
  Forms,
  Test in 'Test.pas' {FrmTest};
 
{$R *.res}
 
begin
  Application.Initialize;
  Application.CreateForm(TFrmTest, FrmTest);
  Application.Run;
end.