Link to home
Start Free TrialLog in
Avatar of shawn857
shawn857

asked on

Need to allow the 'TAB' character as input in an Inputbox...

Hello Experts... is there some way to allow the literal input of the TAB character (Chr(9)) when the user is typing an input string into an InputBox? Currently, hitting the TAB key jumps the cursor to the "OK" and "Cancel" keys.

Thanks!
    Shawn

P.S: I'm using D7.
Avatar of Sinisa Vuk
Sinisa Vuk
Flag of Croatia image

Use OnChange event and check if this word is written - then call:
PostMessage(Self.Handle, WM_NextDlgCtl, 0, 0);

Open in new window

...to act like Tab.
Avatar of shawn857
shawn857

ASKER

Thanks Sinisa, and this will save the TAB character in the string that receives the InputBox function result? I need to save the tab in the result string.

I'm not sure how to use this... could you give an example?

Thanks
    Shawn
Why ?

You could add a button
which does: Edit1.Text := Edit1.Text + Chr(9);
Thanks Geert... but I don't just want to tack a TAB onto the end of a string, I want to capture the user's input and save it to a string... and I want the user to be allowed to enter a TAB character if he needs to. For example, he might type in:

21,{TAB},{TAB},35

... and I need to save that input.

Thanks
   Shawn
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium 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
Don't need to capture everything Geert... just all normal keyboard characters PLUS the tab. No need to capture Delete key or anything like that.

Thanks
    Shawn
You did not clear enough....
in on KeyPress event catch all keys but Tab. For Tab - catch CM_DIALOGKEY message:
type
  TForm1 = class(TForm)
  private
...
    procedure CMDialogKey(var msg: TCMDialogKey); message CM_DIALOGKEY;
  public
    { Public declarations }
  end;
....
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  case key of
    #13: //enter
    begin
       key := #0;  //disable enter
       Edit1.Text := Edit1.Text + '<ENTER>';
    end;
  end;
end;

procedure TForm1.CMDialogKey(var msg: TCMDialogKey);
begin
  if msg.CharCode = VK_TAB then
  begin
    if Edit1.Focused then
    begin
      Edit1.Text := Edit1.Text + '<TAB>';
      msg.Result := 1; //disable Tab
    end
    else
      inherited;   //allow tab     
  end
  else
    inherited; //allow tab     
end;

Open in new window

Ah yes, it looks like just a TMemo is all I need... I didn't know about the "WantTabs" property. That's perfect. Sinisa sorry - a simple TMemo is exactly what I need... I can use a 1-line TMemo instead of the InputBox.

Thanks!
    Shawn
ok, no problem :-) your problem is solved.
Thank you all.

Shawn