Mirror

How to prevent the cursor from jumping to the start of a TDBMemo after setting the charcase property (Views: 7)


Problem/Question/Abstract:

I published the Charcase property of a TDBMemo, but have had a couple of problems. If I set the case to Upper or Lower sometimes, depending on what text is in the memo, no matter where I place the cursor and start typing (dataset in browse mode before this) the cursor jumps to the start of the memo and types there instead. Setting Charcase to normal corrects this. This only happens on a memo that is fairly full with text (the display area that is!). Any ideas why this is happening and how to stop it?

Answer:

This happens even in a normal TDBMemo. My solution is to use the OnEnter event of the TDBMemo:

{ ... }
x := TDBMemo(Sender).SelStart;
if not (TDBMemo(Sender).DataSource.DataSet.State in dsEditModes) then
  TDBMemo(Sender).DataSource.DataSet.Edit;
TDBMemo(Sender).SelStart := x;
TDBMemo(Sender).SelLength := 0;
{ ... }

This seems to solve that problem entirely. First it stores the clicked on location of the memo, and you can see what the rest does.

<< Back to main page