Советы по Delphi

         

КОМПОНЕНТ #2 - TDBCOMBO


Здесь я не собираюсь обсуждать технологию имплантации DBCombo, так как она практически не отличается от той, что была показана выше. Все написанное в пункте #1 имеет силу и здесь. Вот пошагово разработанный код для вашего компонента.

    procedure TForm1.FormCreate(Sender: TObject);
begin
DBLookupCombo1.Visible := False; DBComboBox1.Visible := False; end;

procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect;
Field: TField; State: TGridDrawState); begin
if
(gdFocused in State) then

begin if
(Field.FieldName = DBLookupCombo1.DataField) then
begin
DBLookupCombo1.Left := Rect.Left + DBGrid1.Left; DBLookupCombo1.Top := Rect.Top + DBGrid1.top; DBLookupCombo1.Width := Rect.Right - Rect.Left; DBLookupCombo1.Visible := True; end else if (Field.FieldName = DBComboBox1.DataField) then begin DBComboBox1.Left := Rect.Left + DBGrid1.Left; DBComboBox1.Top := Rect.Top + DBGrid1.top; DBComboBox1.Width := Rect.Right - Rect.Left; DBComboBox1.Visible := True; end end; end;

procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
If
DBGrid1.SelectedField.FieldName = DBLookupCombo1.DataField then DBLookupCombo1.Visible := false else If DBGrid1.SelectedField.FieldName = DBComboBox1.DataField then DBComboBox1.Visible := false; end;

procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if
(key <> chr(9)) then begin if (DBGrid1.SelectedField.FieldName = DBLookupCombo1.DataField) then begin DBLookupCombo1.SetFocus; SendMessage(DBLookupCombo1.Handle, WM_Char, word(Key), 0); end else if (DBGrid1.SelectedField.FieldName = DBComboBox1.DataField) then
begin
DBComboBox1.SetFocus; SendMessage(DBComboBox1.Handle, WM_Char, word(Key), 0); end; end; end;



Содержание раздела