Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi RichEdit Link öffnen (https://www.delphipraxis.net/135465-richedit-link-oeffnen.html)

sk0r 11. Jun 2009 10:26


RichEdit Link öffnen
 
Hoi,

ich würde gerne in einem Fenster, in dem geschrieben wird,
URLs erkennen. Das ist auch nicht schwer, aber wie kann ich
bewerkstelligen, dass der Link mit ShellExecute geöffnen wird,
wenn ich mit der Maus auf den Link fahre und klicke?

MfG: sk0r

fkerber 11. Jun 2009 10:35

Re: RichEdit Link öffnen
 
Hi!

Schau mal hier:
http://delphi.about.com/od/vclusing/l/aa111803a.htm


Grüße, Frederic

RWarnecke 11. Jun 2009 10:52

Re: RichEdit Link öffnen
 
Diese Variante habe ich mal im Internet gefunden :
Delphi-Quellcode:
////////////////////////////////////////////////////////////////////////////////
///
///  If the a url under the mouse cursor and when the left mouse button is used,
///  then open the url in the standard browser
///
procedure TMainForm.RichEditMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (TRichEdit(Sender).Cursor = crHandPoint) and (Button = mbLeft) then
    if pos('http://', TRichEdit(Sender).Hint) > 0 then
      ShellExecute(Application.Handle,'open', PChar(TRichEdit(Sender).Hint), nil, nil, 1);
end;
////////////////////////////////////////////////////////////////////////////////
///
///  To determine if there a url under the mouse cursor and show it in the hint
///  of the TRichEdit component
///
procedure TMainForm.RichEditMouseMove(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];
    if pos('http://', s) > 0 then
    begin
      // 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
      s := Copy(s, i + 1, j - i);
      ShowHint := true;
      Hint := s;
      Cursor := crHandPoint;
    end
    else
    begin
      ShowHint := false;
      Hint := '';
      Cursor := crDefault;
    end;
  end;
end;
erstellt durch Code-Orakel und dem BBCode-Plugin.

DeddyH 11. Jun 2009 11:08

Re: RichEdit Link öffnen
 
Aber wozu sich selbst verbiegen, wenn das Richedit das schon von Haus aus mitbringt? Ich wusste das zugegebenermaßen aber auch nicht, bevor ich den Artikel gelesen habe.

sk0r 11. Jun 2009 11:35

Re: RichEdit Link öffnen
 
Danke, es funktioniert.


Alle Zeitangaben in WEZ +1. Es ist jetzt 08:41 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz