Autor Beitrag
aM0xACiLLiN
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Mi 14.04.04 11:03 
Hi,

ich möchte in meiner Anwendung hyperlinks oder andere begriffe highlighten, also so, dass man darauf klicken kann.
Wenn ich jetzt die Standard-Methode über die WindowsAPI benutze (die man auf so zahlreichen Delphi-Seiten findet) wird leider sogar schon // als Hyperlink erkannt, was für meine Anwendung aber noch lange keiner ist. Ich würde gerne selber bestimmen, was highlighted werden soll, und wie (nicht unbedingt unterstrichen + farbig, aber trotzdem anklickbar). Eventuell langt da ja einfach ein bestimmter code für OnMouseDown, der einem das Wort an Mauszeigerposition zurückgibt aus dem RichEdit.

Wo wir grade dabei sind: Kann man den blinkenden Cursor aus dem RichEdit ganz verstecken, ohne über den Umweg zu gehen, einer anderen Komponente den Focus zuzuweisen?

cu & thx


Zuletzt bearbeitet von aM0xACiLLiN am Mi 14.04.04 12:38, insgesamt 2-mal bearbeitet
ixtreme
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mi 14.04.04 11:58 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
uses Richedit,ShellAPI;

procedure TForm1.RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
  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);
         iCharIndex := Perform(Messages.EM_CHARFROMPOS, 0, Integer(@Pt));
    if iCharIndex < 0 then Exit;
         iLineIndex  := Perform(EM_EXLINEFROMCHAR, 0, iCharIndex);
    iCharOffset := iCharIndex - Perform(EM_LINEINDEX, iLineIndex, 0);
    if Lines.Count - 1 < iLineIndex then Exit;
         s := Lines[iLineIndex];
         i := iCharOffset + 1;
    while (i > 0) and (s[i] <> ' ') do Dec(i);
        j := iCharOffset + 1;
    while (j <= Length(s)) and (s[j] <> ' ') do Inc(j);
        if pos('http://',lowercase(Copy(s, i, j - i))) > 0 then ShellExecute(Application.Handle, 'open', pchar(Copy(s, i, j - i)), nil, nil, SW_SHOW);
  end;
end;


Hiermit funktionierts, der Text wird leider nicht in Farbe/form geändert, aber der Link klick funktioniert!

ixtreme.de
aM0xACiLLiN Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 64



BeitragVerfasst: Mi 14.04.04 12:34 
Hi,

habs nun schon selbst hinbekommen. Tut mir leid, falls du dir Mühe gemacht hast..
Mein Code (etwas kürzer):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure TForm1.RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var tmp:string; c:integer;
const url_prefixes:array[0..3] of string = ('http://','ftp://','https://','www.');
begin
for c:=RichEdit1.SelStart downto 0 do 
 if (copy(RichEdit1.text,c,1) = ' ') then break else tmp:=copy(RichEdit1.Text,c,1)+tmp;
for c:=RichEdit1.SelStart+1 to length(RichEdit1.text) do 
 if (copy(RichEdit1.text,c,1) = ' ') then break else tmp:=tmp+copy(RichEdit1.Text,c,1);
for c:=0 to 3 do if (copy(tmp,1,length(url_prefixes[c])) = url_prefixes[c]) then
ShellExecute(Handle, 'open', PChar(tmp), nil, nil, SW_SHOWNORMAL);
end;


cu