?
Solved

Where's my caret gone?

Posted on 2001-06-13
9
Medium Priority
?
269 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 200 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 13 hours left to enroll

762 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