Solved

About HyperLink

Posted on 1998-09-16
5
162 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

831 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