Link to home
Start Free TrialLog in
Avatar of thooloon
thooloon

asked on

How can i use Tab key in RichEdit Delphi

In my application  i am  using a dbRichText Control, i want to use the Tab Key just like word applications do, how can i use this function, when i press the tab key the focus goes to another control,

Best Regards
Thooloon
Avatar of Ralf Klatt
Ralf Klatt
Flag of Germany image

Hi,

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #0 then begin
    if (Sender is TDBGrid) then
      TDBGrid(Sender).Perform(WM_KeyDown,VK_Tab,0)
    else
      Perform(Wm_NextDlgCtl,0,0);
  end;
end;


Best regards,
Raisor
Avatar of thooloon
thooloon

ASKER

I am using a DBRichEdit Control connected to a database the above solution does not work,
thanks
Thoo
Hi,

It wasn't meant to be a working solution ... it was a simple example showing how the tab key works in delphi ... you'll have to apply the example's logic to your own code to make it work!


Best regards,
Raisor

i have applied the logic anfd used the code in the keypress event of the richedit control but it does not work

regards
Thooloon
Hi,

Could you provide the peace of code you've used, please?


Best regards,
Raisor
Hi,

This is my code, please check

procedure TForm2.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #0 then begin
    if (Sender is TrichEdit) then
      TrichEdit(Sender).Perform(WM_KeyDown,VK_Tab,0)
    else
      Perform(Wm_NextDlgCtl,0,0);
  end;
end;


Best Regards
Thooloon
Hi,

I'm not really a crack using Delphi (a friend of mine almost is a crack! ... I can't reach him currently!) ... but one thing I've seen is that you're using:

procedure TForm2.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #0 then begin
    if (Sender is TrichEdit) then
      TrichEdit(Sender).Perform(WM_KeyDown,VK_Tab,0)
    else
      Perform(Wm_NextDlgCtl,0,0);
  end;
end;

... you might try ...

procedure TForm2.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #0 then begin
    if (Sender is TRichEdit) then
      TRichEdit(Sender).Perform(WM_KeyDown,VK_Tab,0)
    else
      Perform(Wm_NextDlgCtl,0,0);
  end;
end;

... just in case there's some "case sensitivity" to respect!


Best regards,
Raisor
Hi,

This one should do it as "Key = #9" obviously is the "Tab-Key" ...

procedure TForm2.RichEdit1KeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #9 then begin
    Key := #0;
    if (Sender is TRichEdit) then
      TRichEdit(Sender).Perform(WM_KeyDown,VK_Tab,0)
    else
      Perform(Wm_NextDlgCtl,0,0);
  end;
end;


Best regards,
Raisor
ASKER CERTIFIED SOLUTION
Avatar of Shane Russell
Shane Russell
Flag of United Kingdom of Great Britain and Northern Ireland image

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
thanks all for the help,

Best Regads
Thooloon
Thanks for the grade and points ! Very much appreciated :)
... my best regards @gecko ;-))
what makes you say that Raisor ? :D
I cant believe the amount of points I have gotten in the last month and being in that top 15 list is a huge achievment for me :) I must admit :) I thouroughly LOVE programming and I really want to learn as much as possible about programming ! I guess I was always taught that the simplest solutions are to some extent the best ones :) Just depends on the problem at hand :)
Hi,

... it was definitely nothing offending that made me state "my best regards @gecko" <- thooloon decided to give the points to you ... and that's absolutely ok for me! ... the only thing astonishing me (positively!) was the simpleness of your answer ... as the original question was about a Tab KEY that should have sent the focus to another control ;-}


Best regards,
Raisor
lol - Not sure if you have ever heard of this saying but "KISS" which means " Keep it simple stupid " :) Anyway, Be great to stay in touch with you, I will  most likey learn quite a lot from you not to mention other experts on this forum and by subscribing to other questions :)

I was not offended, I just wasn't expecting the points to start with because I havent really used delphi that much and I wasnt even sure that the property existed in delphi, I just know its a one in visual basic and figured I would put that there just to point it out :)

I gotta admit, personally I love the simple answers :). Call me lazy or w/e but I like them a lot lol :)

In all honesty I thought you or one of the other experts would get the points because all your answers and suggestions were in code and not really having used delphi, the coding made a little bit of sense to me but I would really have to use Delphi for me to really understand what it all did , etc :)

I am working on it though LOL :)
Hi,

... thanks for your feedback, Gecko ... I'm happy that thooloon has received what he was looking for!


Best regards,
Raisor
Me 2, I was shocked myself when I opened my email and it said Good Answer! for this question, I was like ok I am fully awake and no Im not on drugs lol. Then I was like ok let me go look to make sure I am not tripping lol.

It was great meeting you though Raisor ! as an expert and as a fellow programmer !

Kind regards

Gecko
Hi Gecko and Raisor,

Actually i am very thankfull to both of you, coz u both has helped me. specially Raisor took a lot of effort to help me.

Best Regards
Mohamaed Thooloon
Raisor is great with helping, sticks with you till you get the problem sorted out !