Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3340092
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:34:04+00:00 2026-05-18T00:34:04+00:00

Sorry if there is already made such question earlier, but I have no time

  • 0

Sorry if there is already made such question earlier, but I have no time at the moment to dig in stackoverflow db …

So, I have this code:

procedure TForm1.GraphPrevBtnMouseEnter(Sender: TObject);
var frm_PrevBtn : TForm;
begin
  GraphPrevBtn.Width := 75;
  if z = 0 then begin
    frm_PrevBtn := TForm.Create(nil);
    with frm_PrevBtn do begin
      Name := 'frm_PrevBtn';
      BorderStyle := bsNone;
      Position := poDesigned;
      Top := Form1.Top + GraphprevBtn.Top + (form1.Height - Form1.ClientHeight) - 3;
      Left := Form1.Left + GraphprevBtn.Left + 3;
      Width := GraphprevBtn.Width; Height := GraphprevBtn.Height; transparentColor := True; TransparentColorValue := clbtnFace;
      Show;
    end;
    GraphPrevBtn.Parent := frm_PrevBtn;
    if GetLastError = 0 then z := frm_prevBtn.GetHashCode;
  end;
end;

procedure TForm1.GraphPrevBtnMouseLeave(Sender: TObject);
    var frm_PrevBtn_H : THandle;
    begin
    // if form is created then- if mouse is under button then- if z = formshashcode ( form is on creatin stage )
      if not (FindVCLWindow(Mouse.CursorPos) = GraphPrevBtn) and ((FindControl(FindWindow('TForm','frm_PrevBtn')) as TForm).Visible = True) and (GraphPrevBtn.Parent = FindControl(FindWindow('TForm','frm_PrevBtn')) as TForm) then begin // if mouse is not under graphprevBtn
        ShowMessage(FindVCLWindow(Mouse.CursorPos).Name); // 
        if z = 112                                                       // then if form is created
        then begin
            GraphPrevBtn.Parent := Form1;
            GraphPrevBtn.bringtoFront;
            GraphPrevBtn.Top := 29; GraphPrevBtn.Left := 226;
            (FindControl(FindWindow('TForm','frm_PrevBtn')) as TForm).Free;
            if GetLastError = 0 then z := 0;
          end;
      end;
   end;

So, my wish is the following:
When I enter this GraphPrevBtn with mouse, form is created. As for is created, the focus goes from Control to new form. As focus is to new form, the OnMouseLeave event is fired. As event is fired, it should destroy the form, BUT ONLY IF user ( NOT active control / focus ) actually leaves control by mouse.

What happens now is that either new forms is not destroyed at all or both events goes infinite loop ( *frm_PrevBtn* is created and destroyed again and again and again…).

What would be best solution?

My idea is to get new forms rect and check whenever mouse is inside this rect. If it is, then perform allow OnMouseLeave event, otherwise deattach it … would it work?

As much I tried with these samples:

  1. http://delphi.about.com/od/windowsshellapi/a/get-active-ctrl.htm
  2. http://delphi.about.com/od/delphitips2010/qt/is-some-delphi-tcontrol-under-the-mouse.htm

    • No luck. Where is the problem … ?

Remarks: global var z : byte;

P.S. Thanks for negative votes … great motivation to use this site in future …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:34:04+00:00Added an answer on May 18, 2026 at 12:34 am

    Mouse enters on ‘GraphPrevBtn’, you create a form over the button. As soon as this form becomes visible, since mouse is not anymore over ‘GraphPrevBtn’, ‘OnMouseLeave’ is fired. You destroy the new form and now mouse is again on the button so ‘OnMouseEnter’ is fired, hence the infinite loop.

    As a solution, you can move the form disposing code to ‘OnMouseEnter’ of Form1:

    procedure TForm1.FormMouseEnter(Sender: TObject);
    begin
      if z = 112
      then begin
        GraphPrevBtn.Parent := Form1;
        [...]
    

    .. and what’s with the ‘GetLastError’, it seems fully irrelevant. If you’re going to use it, at least set last error to ‘0’ by calling GetLastError or SetLastErrorbefore beginning your operation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for this question. There is a lot of information but unfortunately I haven't
Sorry for this silly question, but is there any way to restrict using directives
Sorry if this is a stupid question, but is there an easy way to
Sorry for this simple question, but I can't solve it... There is an example:
Sorry for asking it again, there are already some questions about this keyword. But
I know there are already some threads with this question, but none was helpful
I'm sorry if this question has already been answered but I couldn't find it.
Sorry for newbie question but is there a way to import someone else commit
Sorry if this is a dupe. There are many similar questions but it seems
I'm really sorry. This must seem like an incredibly stupid question, but unless I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.