Setfocus in edit box of TFindDialog

Posted on 2011-05-05
Last Modified: 2012-05-11
When executing TFindDialog, how do I get the cursor is in the edit box without clicking in the edit box. I know FindText will put text in the box but I want the cursor there too.
Question by:Dennis_Treacy
    LVL 24

    Expert Comment

    LVL 4

    Expert Comment

    I think Dennis_Treacy is talking about the EditBox in the TFindDialog...
    I looked at the components[] property, but it counts 0...

    TFindDialog calls the function from
    function FindText; external commdlg32  name 'FindTextA';


    FFindHandle := FFindReplaceFunc(FFindReplace);

    So we have to look at the child windows of FFindHandle, But it's private :)..

    An ugly approach:
      Copy all the codes of TFindDialog to a new unit,

    Then, by the help of FindWindowEx function acquire the handle of EditBox,
    Finally call the function Windows.SetFocus(HandleOfEditBox);

    However, If i execute the FindDialog, The focus is on EditBox..



    LVL 4

    Expert Comment

    Ugly approach became very ugly when i tried :)..
    Have to copy half of the unit Dialogs...So let's forget it...
    LVL 36

    Expert Comment

    by:Geert Gruwez
    if you run like this the edit box in the find dialog will be focused


    Author Comment

    Edit1 is an undeclared identifier. Is there an actual published name for that edit box component?
    LVL 32

    Accepted Solution


    I'm not sure I understand but, whenever you call FindDialog.Execute, the cursor will be placed in the FinDialog Edit box unless you are specifically moving the focus somewhere else

      FindDialog1.FindText := 'Memo';
    After this code, focus is on the edit box of finddialog

    On the other hand, if you change the focus, then the edit box looses the focus
      FindDialog1.FindText := 'Memo';
    Now the focus is on Memo1

    Author Closing Comment

    FindDialog1.Execute(self.Handle) is the answer;

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Suggested Solutions

    The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
    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…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    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…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now