Solved

MouseDown on TDBComboBox

Posted on 2001-08-01
2
535 Views
Last Modified: 2010-04-06
I want to trap the OnMouseDown on a TDBComboBox. I want to clear the box if right-mouse button is clicked on it.

There is no event for mousedown... how do I trap it?

thanks for the help.
0
Comment
Question by:espeterson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6341219
Try this:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, DBCtrls;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure MyDBComboBoxMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TMyDBComboBox = class(TDBComboBox)
  published
    property OnMouseDown;
  end;

var
  Form1 : TForm1;
  MyDBComboBox : TMyDBComboBox;

implementation

{$R *.DFM}

procedure TForm1.MyDBComboBoxMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if ssRight in Shift then
  begin
    ShowMessage('Right Mouse Button has been Clicked...')
    // Do whatever when right mouse button is clicked...
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyDBComboBox := TMyDBComboBox.Create(self);
  with MyDBComboBox do
  begin
    Parent := Form1;
    Left := 10;
    Top := 10;
    Width := 145;
    Height := 21;
    // Define any other properties...
  end;
  MyDBCombobox.OnMouseDown := MyDBComboBoxMouseDown;
end;

end.

Cheers,

Alan
0
 
LVL 5

Accepted Solution

by:
alanwhincup earned 100 total points
ID: 6341250
Just realised that my above example did'nt totaly work so i redid it:

to make it work you just have to have a Popupmenu on the form and use the below code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, DBCtrls, Menus;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    procedure FormCreate(Sender: TObject);
    procedure MyDBComboBoxMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure PopupMenu1Popup(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

type
  TMyDBComboBox = class(TDBComboBox)
  published
    property OnMouseDown;
  end;

var
  Form1 : TForm1;
  MyDBComboBox : TMyDBComboBox;

implementation

{$R *.DFM}

procedure TForm1.MyDBComboBoxMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if ssRight in Shift then
    MyDBComboBox.Clear;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyDBComboBox := TMyDBComboBox.Create(self);
  with MyDBComboBox do
  begin
    Parent := Form1;
    Left := 10;
    Top := 10;
    Width := 145;
    Height := 21;
    PopupMenu := PopupMenu1;
    MyDBComboBox.Text := 'Test';
    OnMouseDown := MyDBComboBoxMouseDown;
    // Define any other properties...
  end;
end;

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  MyDBComboBox.Clear;
end;

end.

If you dont want to use all this code then you can just put down a DBComboBox and a PopupMenu on a form, and then Assign the PopupMenu's name value to PopupMenu property in DBComboBoxs properties. After youve done that use the below code in the PopupMenu's Popup event:

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  MyDBComboBox.Clear;
end;

This will work when you right click on the editable part of the dbcombobox but not anywhee else.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Find and Replace Stream with 0s 8 73
Base1 Encode/Decode 3 86
Graphics32 under Delphi 10.1 Berlin 2 126
Tvertscrollbox like a whatsapp layout delete messages 1 38
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question