Solved

Where's my caret gone?

Posted on 2001-06-13
9
257 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

932 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

12 Experts available now in Live!

Get 1:1 Help Now