Tja, das ist mal kein Delphi-Problem, sondern eins der
API.
Die MSDN schrieb zu EM_SETSEL The start value can be greater than the end value. The lower of the two values specifies the character position of the first character in the selection. The higher value specifies the position of the first character beyond the selection.
The start value is the anchor point of the selection, and the end value is the active end. If the user uses the SHIFT key to adjust the size of the selection, the active end can move but the anchor point remains the same.
P.S.: Ich hab da mal was gebastelt:
Delphi-Quellcode:
procedure SetSel(Edit: TEdit; Start, Stop: Integer);
var
i: Integer;
KeyboardState: TKeyboardState;
begin
Edit.Perform(EM_SETSEL, Start, Start);
GetKeyboardState(KeyboardState);
KeyboardState[VK_SHIFT] := $80;
SetKeyboardState(KeyboardState);
if Start > Stop then
for i := Start downto Succ(Stop) do
begin
Edit.Perform(WM_KEYDOWN, VK_LEFT, 0);
Edit.Perform(WM_KEYUP, VK_LEFT, 0);
end;
if Start < Stop then
for i := Start to Pred(Stop) do
begin
Edit.Perform(WM_KEYDOWN, VK_RIGHT, 0);
Edit.Perform(WM_KEYUP, VK_RIGHT, 0);
end;
SetKeyboardState(KeyboardState);
end;