Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to modify TEdit to accept control chars...

Status
Not open for further replies.

agual

Programmer
Nov 1, 2001
77
ES
This is: chars below ASCII 32. They should be entered with CTRL-char and would be displayed as [07].
Please just a quick hack to inspire me. I'm not as fluent in Delphi as I need to become...
Antoni
 
Assign a handler to the OnKeyPress event for the TEdit that does something like this:

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if key < #32 then
begin
Edit1.Text := Edit1.Text+'[0'+IntToStr(Ord(key))+']';
Key := #0;
end;
end;
 
I suspect that the solution proposed by Zathras will not meet all your requirements.

The control character has actually been converted to the three characters [ 7 ] (to use your example). When your program reads the edit field it will get three characters when you were probably only wanting one character.

There is also the problem of what to do when the user hits backspace or the delete key. You actually need to delete three characters in the edit field in one hit but as it stands only one character will be deleted.

I suggest that the best way is to write a new component that is descended from TEdit which provides the features that you want. If you are new to Delphi you may find this quite challenging but you would learn a lot. Developing components is often rewarding.

Andrew
 
Thanks for your help.
I have an idea:
A hidden TrueText field that gets the real chars typed...
To delete something the TrueText is read and if a control char is at that place 4 chars are deleted in the text.
After all I need the True Text to send it thru the comms port. The app I'm doing is a comms tester.. Antoni
 
Yes, that sounds like the way to do it.

I would recommend that you make it a component (or at least a class) if you can. It will probably be quite a useful component and you may want to use it in other applications (or in several places in your comms tester).

I frequently find that code I've written should have been put in a class but I was always in too much of a hurry to produce a working program. Later on I regret this haste because time saved in coding is wasted several times over in longer debugging/testing plus the time spent in rewriting it as a properly designed class.

Andrew
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top