was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

43 Visitors Online


 
...das Wort unter dem Maus-Cursor in einem TRichEdit auslesen?
Autor: Thomas Stutz
[ Tip ausdrucken ]  

Tip Bewertung (13):  
     


uses
 
RichEdit;
 
procedure TForm1.RichEdit1MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
var
  
iCharIndex, iLineIndex, iCharOffset, i, j: Integer;
  Pt: TPoint;
  s: string;
begin
  with 
TRichEdit(Sender) do
  begin
    
Pt := Point(X, Y);
    // Get Character Index from word under the cursor
    
iCharIndex := Perform(Messages.EM_CHARFROMPOS, 0, Integer(@Pt));
    if iCharIndex < 0 then Exit;
    // Get line Index
    
iLineIndex  := Perform(EM_EXLINEFROMCHAR, 0, iCharIndex);
    iCharOffset := iCharIndex - Perform(EM_LINEINDEX, iLineIndex, 0);
    if Lines.Count - 1 < iLineIndex then Exit;
    // store the current line in a variable
    
s := Lines[iLineIndex];
    // Search the beginning of the word
    
i := iCharOffset + 1;
    while (i > 0) and (s[i] <> ' ') do Dec(i);
    // Search the end of the word
    
j := iCharOffset + 1;
    while (j <= Length(s)) and (s[j] <> ' ') do Inc(j);
    // Display Text under Cursor
    
Caption := Copy(s, i, j - i);
  end;
end;


 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners