?
Solved

About HyperLink

Posted on 1998-09-16
5
Medium Priority
?
169 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Integration Management Part 2
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

850 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