Solved

Where's my caret gone?

Posted on 2001-06-13
9
256 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
  • 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 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

17 Experts available now in Live!

Get 1:1 Help Now