Solved

Where's my caret gone?

Posted on 2001-06-13
9
267 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
Technology Partners: 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

Technology Partners: 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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

718 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