?
Solved

How declare global MouseDown event?

Posted on 1997-07-19
1
Medium Priority
?
327 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
[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
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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