Link to home
Start Free TrialLog in
Avatar of dluedi
dluedi

asked on

"Instant help"

Hi
If you've got Delphi 5.0 and you type for example edit1.   and wait a moment a help box will show up,
showing you all the properties, functions and procedures you can use.
=>How can I do this e.g. in a memo or richtext component?
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of image

Hello

  that's found in all component in delphi, edit1, or rich1., and any other components will show you the tooltip help box, but i think you don't type the correct name for the memo or richedit (not richtext like you wrote)
so when you type RichEdit. it will not give you any help, but the right name is RichEdit1., just insure in the component name

Mohammed
Avatar of karouri
karouri

listening..
btw, I think dluedi means that he wants to implement the same way as Delphi does in one of his programs. that is, when he presses . the program should be able to show him the options available..

If that is right, then this can be done by doing the following:
*In OnKeyPress, a timer is initiated if a '.' is pressed and is disabled if another key is pressed
* In the timer's ontimer he should 'show' the text linked to the word immediately before the '.', which may be contained in a stringlist e.g.
* the word before can be extracted by going from the dot backward till the space
* 'show' by assigning to hint and showing hint

k
Avatar of dluedi

ASKER

Yes karouri you got the point, maybe you can just let a listbox occur at the position of the the dot, then the user can choose from a listbox???
Try this code and comment..

//unit1.dfm
object Form1: TForm1
  Left = 192
  Top = 107
  Width = 544
  Height = 375
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Memo1: TMemo
    Left = 96
    Top = 32
    Width = 305
    Height = 289
    Lines.Strings = (
      'Memo1')
    TabOrder = 0
    OnKeyPress = Memo1KeyPress
  end
  object ListBox1: TListBox
    Left = 432
    Top = 88
    Width = 81
    Height = 41
    Ctl3D = False
    IntegralHeight = True
    ItemHeight = 13
    Items.Strings = (
      'a'
      'along'
      'and '
      'comes'
      'hero'
      'then')
    ParentCtl3D = False
    Sorted = True
    TabOrder = 1
    Visible = False
    OnKeyPress = ListBox1KeyPress
  end
  object Timer1: TTimer
    Enabled = False
    Interval = 2000
    OnTimer = Timer1Timer
    Left = 24
    Top = 80
  end
end

//unit1.pas
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    ListBox1: TListBox;
    Timer1: TTimer;
    procedure Memo1KeyPress(Sender: TObject; var Key: Char);
    procedure Timer1Timer(Sender: TObject);
    procedure ListBox1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
    CurrentLetter:integer;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Memo1KeyPress(Sender: TObject; var Key: Char);
begin
  Timer1.Enabled:=Key='.';
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  P:TPoint;
begin
  Timer1.Enabled:=false;
  GetCaretPos(P);
  P:=ScreenToClient(Memo1.ClientToScreen(P));
  with ListBox1 do
  begin
    Left:=P.x+2;
    Top:=P.y-Memo1.Font.Height+2;
    BringToFront;
    Visible:=true;
    SetFocus;
  end;
  CurrentLetter:=Length(Memo1.Text);
end;

procedure TForm1.ListBox1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key in [#27,#13,' ','.'] then
  begin
    if Key<>#27 then
    begin
      Memo1.SelStart:=CurrentLetter;
      Memo1.SelLength:=Length(Memo1.Text);
      Memo1.SelText:=ListBox1.Items[ListBox1.ItemIndex];
    end;
    ListBox1.Visible:=false;
    Memo1.SetFocus;
    if Key in [#27,#13] then
      Key:=#0;
  end;
  SendMessage(Memo1.Handle,WM_CHAR,integer(Key),0);
end;

end.
Avatar of dluedi

ASKER

Hello, your code works nearly perfectly. Only if you press two times "." then there is an error!!!
ASKER CERTIFIED SOLUTION
Avatar of karouri
karouri

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dluedi

ASKER

I didn't try your new code yet...but it will sure work. You've been waiting for long...so here you are! In future, please don't use propose question, because I couldn't tell to you that you have to wait for a while...thx
:)dluedi