Solved

About HyperLink

Posted on 1998-09-16
5
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

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