?
Solved

How declare global MouseDown event?

Posted on 1997-07-19
1
Medium Priority
?
335 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 600 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month16 days, 6 hours left to enroll

850 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