Solved

How declare global MouseDown event?

Posted on 1997-07-19
1
312 Views
Last Modified: 2010-04-03
Hi!

I'm developing an application with several forms all having similar appearance. On these forms there are a couple of panels. The problem: When I press the mouse button on any of these panels (located on different forms) I want the OnMouseDown event for each panel to call the same handler procedure which is located in the application's main unit. How should I do this? I haven't managed to declare the procedure in such a way that the program compiles correctly.
Please help, thanks.
0
Comment
Question by:Dippen
1 Comment
 
LVL 5

Accepted Solution

by:
ronit051397 earned 200 total points
ID: 1339282
1. Create a project with 2 forms: fMain, Form2.
2. On the project file write:
program test1;

uses
  Forms,
  uMain in 'uMain.pas' {fMain},
  u2 in 'u2.pas' {Form2};

{$R *.RES}

begin
  Application.Initialize;
  Application.CreateForm(TfMain, fMain);
  Application.Run;
end.

3. On the mainform create a button and create a procedure which moves panels, as follows:

unit uMain;

interface

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

type
  TfMain = class(TForm)
    Button1: TButton;
    Procedure MovePanel(FObject: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fMain: TfMain;

implementation
uses u2;
{$R *.DFM}

Procedure TfMain.MovePanel(FObject: TObject);
begin
  with TPanel(FObject) do
  begin
    ReleaseCapture;
    Perform(WM_SysCommand, $F012, 0);
  end;
end;

procedure TfMain.Button1Click(Sender: TObject);
begin
  Application.Createform(TForm2,Form2);
  Form2.ShowModal;
end;

end.
4. On the second form place 2 panels and write:
unit u2;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls;

type
  TForm2 = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Panel2MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses uMain;

{$R *.DFM}

procedure TForm2.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  fMain.MovePanel(Sender);
end;

procedure TForm2.Panel2MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  fMain.MovePanel(Sender);
end;

end.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now