Solved

About HyperLink

Posted on 1998-09-16
5
160 Views
Last Modified: 2010-04-06
Hard to simplify in a sentence.
Here is my problem:

I have a database, for example:
viva
forever
love

Then, I type in TRichEdit:
I love you forever.

This is what I want:
when I move my mouse on word "love" or "forever",
the mouse pointer changes to crHandPoint.

So, how to do that?
I hope you can understand my point.
Sorry for the incovenience, since English is not natural
language in my country...

Like usual, waiting for help from any expert...



0
Comment
Question by:stinger_60284
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:gysbert1
ID: 1340023
A few thoughts, might help ...

1) Hook into the MouseMove event of the control and check do all your processing here ...
2) Create a list with all the items in the database that you regularly update (how often will the dabase change ?)
3) If no method exixts to find text at a certain location you will have to calculate it (bummer) using the font attributes and the position in the control...
4) You know how easy it is to change the cursor so I do not have to go into that !

0
 
LVL 4

Accepted Solution

by:
erajoj earned 50 total points
ID: 1340024
Hi,
Here's a simple way to do it.
It works on both TRichEdit and TMemo:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    Slask1: TRichEdit;
    Richedit1: TMemo;
    procedure Slask1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormCreate(Sender: TObject);
  private
    m_ValidToken: TStringList;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Slask1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
const
  VALIDCHAR = [ '0'..'9', 'A'..'Z' ];
var
  sText, sToken: string;
  iPos, iStartPos, iLength : Integer;
  POINTL : TPoint;
  Lines  : TStrings;
begin
  if ( Sender is TRichEdit ) then begin
    POINTL := Point( X, Y );
    iPos  := SendMessage( TRichEdit( Sender ).Handle, EM_CHARFROMPOS, 0, Integer( @POINTL ) );
  end else if ( Sender is TMemo )
  then iPos := SendMessage( TMemo( Sender ).Handle, EM_CHARFROMPOS, 0, MakeLParam( X, Y ) )
  else begin
    ( Sender as TControl ).Cursor := crIBeam; // restore cursor
    Exit; // no need to continue
  end;
  sText := TCustomMemo( Sender ).Text;

  if ( iPos = -1 ) then // no char hit
  begin
    ( Sender as TControl ).Cursor := crIBeam; // restore cursor
    Exit; // no need to continue
  end;

  iStartPos := LOWORD( iPos ) + 1; // string offset +1
  iLength   := 1;
  if not ( UpCase( sText[ iStartPos ] ) in VALIDCHAR ) then // no valid char hit
  begin
    ( Sender as TControl ).Cursor := crIBeam; // restore cursor
    Exit; // no need to continue
  end;

  while ( iStartPos > 0 ) and ( UpCase( sText[ iStartPos ] ) in VALIDCHAR ) do Dec( iStartPos ); Inc( iStartPos );
  while ( iStartPos + iLength < Length( sText ) ) and ( UpCase( sText[ iStartPos + iLength ] ) in VALIDCHAR ) do Inc( iLength );

  sToken  := Copy( sText, iStartPos, iLength );
  if ( m_ValidToken.Find( sToken, iPos ) )
  then ( Sender as TControl ).Cursor := crHandPoint
  else ( Sender as TControl ).Cursor := crIBeam;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  m_ValidToken := TStringList.Create;
  with m_ValidToken do begin
    Sorted := True; // enable fast binary search
    Add( 'Love' );
    Add( 'Forever' );
  end;
end;

end.

/// John
0
 
LVL 2

Expert Comment

by:gysbert1
ID: 1340025
That looks exactly right !

I would accept it ... (Definate A  ;^)
0
 
LVL 4

Expert Comment

by:erajoj
ID: 1340026
Well, hold your horses, try it out first. I haven't tested it yet....

/// John
0
 

Author Comment

by:stinger_60284
ID: 1340027
Okay John, I believe in gysbert1.
Btw, if there's a mistake, i'll ask you...
:)

Thanks for your kindness!!!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now