Solved

How declare global MouseDown event?

Posted on 1997-07-19
1
320 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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