Solved

Where's my caret gone?

Posted on 2001-06-13
9
266 Views
Last Modified: 2010-04-06
I've lost my caret.

Here's how I did it.

1. Drop two TEdits onto a form
2. In the OnExit Event of Edit1 add the following code...

  Application.MessageBox( 't','tt', mb_ok );


Run the application.  Select Edit1 Then edit2

The Message box is shown, click the OK button, and hey presto the Caret has dissapeared!



What can I do yo get my caret back.  p.s. I want to use the Application.Messagebox command and not the ShowMessage or MessageDLG command!
0
Comment
Question by:Colin_Dawson
[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
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 8

Accepted Solution

by:
TOndrej earned 50 total points
ID: 6186110
you could post a custom message to the form, e.g.

const
  AM_MSGBOX = WM_USER + 101;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    procedure Edit1Exit(Sender: TObject);
  private
    procedure AMMsgBox(var Message: TMessage); message AM_MSGBOX;
  public
  end;

implementation

procedure TForm1.AMMsgBox(var Message: TMessage);
begin
  Application.MessageBox( 't','tt', mb_ok );
end;

procedure TForm1.Edit1Exit(Sender: TObject);
begin
  PostMessage(Handle, AM_MSGBOX, 0, 0);
end;

HTH
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6186134
guessing, no one from the edits has the focus,
whereas the caret only appears, if the edit is focused

just press on tabkey once
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 6186148
hi kretzschmar,
wrong guess, Edit2 is focused but its caret is hidden, you'll see if you type a character
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:Colin_Dawson
ID: 6186166
I've found another possibility...  Add these two lines of code immediatly after the Application.Messagebox.

  postmessage(Handle,WM_NEXTDLGCTL,0,0);
  postmessage(Handle,WM_NEXTDLGCTL,1,0);


However, this is no good as the message actually shifts focus to the next control then back.  As I've only got two controls, I get a recurring messagebox problem.
0
 
LVL 4

Author Comment

by:Colin_Dawson
ID: 6186172
TOndrej

So far you solution is the best, but It's a little messy, I noticed that the user can actually see the second edit box highlight before the messagebox is shown.

Also I'm looking for something that I can wrap as a single function call that will sort out the problem.

But so far you in the lead.  If I can't get a really good solution I'll have to build my own component that hooks into the message loop! But that's really messy :-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6186174
hi tondrej,

didn't have a delphi installed here,
therefore shooting in the dark

but you will be right

:-)
0
 
LVL 4

Expert Comment

by:DMN
ID: 6186761
Calling MessageBox not only removes the caret but also prevent you control from calling OnEnter event. There is a simple solution of both problems:

procedure TForm1.Edit1Exit(Sender: TObject);
begin
  Application.MessageBox('qq','qq',mb_ok);
  if Assigned(ActiveControl) then
    PostMessage(ActiveControl.Handle,WM_SETFOCUS,0,0);
end;


0
 
LVL 4

Author Comment

by:Colin_Dawson
ID: 6190107
This is the solutions that I found on another site.  I tried it and this works perfectly.

PostMessage(GetFocus, WM_SETFOCUS, TWinControl(Sender).Handle, 0);



I've decided to award the points to TOndrej as this was also a good answer, and very quick!

Thanks to all for your help.
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 6190186
Much better than my proposed solution :-)
Thanks for the points.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 92
Delphi: ForceDirectory plain function 7 50
Delphi and Access based Enumeration 9 78
DBCtrlGrid, Delphi, Scroll 8 59
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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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