Home
What's New
Delphi 3.0 Tips
Questions
Development Tools
Links

Turning a Memo into a "hyperlink"

The main difference between turning a Label and a Memo into a hyperlink is a Memo can recieve focus.

To turn a Memo into a hyperlink:

  1. Change the BorderStyle to bsNone
  2. Change the Color to clBtnFace
  3. Change the label's font property to make it blue and under lined or whatever you think a hyperlink should look like
  4. Change Cursor to crHandPoint
  5. Change ReadOnly to true
  6. Design a PopUp menu for it without useless Menus (since ReadOnly is true) like Undo, Delete, Cut, and Paste (and possibly Select All depending on excactly how you implement you hyperlink)
  7. Add the code, which is given below, for various events (assuming the Memo is named EMailMemo)
//The "real" power of the hyperlink is in clicking it
procedure TForm.EMailMemoClick(Sender: TObject);
begin
  {possibly Close the form here}
  ShellExe ('mailto:' + EMailMemo.Text + '?subject=Code%20Edit');
end;

procedure TForm.EMailMemoEnter(Sender: TObject);
begin
  EMailMemo.SelectAll;//so the user can see it's focused
end;

procedure TForm.EMailMemoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Key = VK_INSERT) and (ssCtrl in Shift) then exit;//allow Memo to copy
  if Key = VK_ESCAPE then Close;//optional like before
  Key := 0;//don't allow other Key processing
end;

{pressing enter should do the same things a clicking the hyperlink}
procedure TForm.EMailMemoKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then EMailMemo.OnClick (Sender);
end;