Einzelnen Beitrag anzeigen

Benutzerbild von Stevie
Stevie

Registriert seit: 12. Aug 2003
Ort: Soest
4.016 Beiträge
 
Delphi 10.1 Berlin Enterprise
 
#9

Re: In Edit Feld künstlich einen Teil markieren

  Alt 15. Mär 2005, 09:32
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;
Stefan
“Simplicity, carried to the extreme, becomes elegance.” Jon Franklin

Delphi Sorcery - DSharp - Spring4D - TestInsight
  Mit Zitat antworten Zitat