Mega Code Archive

 
Categories / Delphi / VCL
 

Change keys pressed in a TMemo

Title: Change keys pressed in a TMemo Question: When you insert an accented letter into a HTML it should be converted into an extended code for international use. That will help everyone who will build an HTML editor Answer: Just add this to your memo keypress event: Procedure TForm1.Memo1KeyPress( Sender: TObject; Var Key : Char ); Const UnSup = #171#187#193#225#194#226#198#230#192#197#229#195#227#196#228#199#231#162#169#20 + #233#202#234#200#232#203#235#205#237#206#238#204#236#207#239#60#209#241#211#243 + #212#244#210#242#216#248#213#245#214#246#34#174#223#218#250#219#251#217#249#220 + #252#255; Supported : Array[ 0..61 ] Of String = ( '«', '»', 'Á', 'á', 'Â', 'â', 'Æ', 'æ', 'À', 'Å', 'å', 'Ã', 'ã', 'Ä', 'ä', 'Ç', 'ç', '¢', '©', 'É', 'é', 'Ê', 'ê', 'È', 'è', 'Ë', 'ë', 'Í', 'í', 'Î', 'î', 'Ì', 'ì', 'Ï', 'ï', ' 'Ñ', 'ñ', 'Ó', 'ó', 'Ô', 'ô', 'Ò', 'ò', 'Ø', 'ø', 'Õ', 'õ', 'Ö', 'ö', '"', '®', 'ß', 'Ú', 'ú', 'Û', 'û', 'Ù', 'ù', 'Ü', 'ü', 'ÿ' ); Var P : Integer; Begin P := Pos( Key, UnSup ); If ( P 0 ) Then Begin Memo1.SetSelTextBuf( PChar( Supported[ P - 1 ] ) ); Key := #0; End; End; Obviously this can be ported to every type of char substitution. If you really use it I raccomend that you insert into the array all special symbols!