Mega Code Archive

 
Categories / Delphi / Examples
 

How to get a Euro currency symbol using Alt+5

Title: How to get a Euro currency symbol using Alt+5 Question: How to get a Euro currency symbol in a Memo, RichEdit or Edit using the Alt+5key-combination Answer: How to get a Euro currency symbol in a Memo, RichEdit or Edit using the Alt + 5 key-combination? Since 1/1/2002 most of the countries in Europe (e.g. Germany, France, Spain, Italy, Greece, Holland, Belgium) have a common currency value, the so called "Euro". Windows supports this Euro currency value since version 98, for earlier versions (e.g. 95) you can get a patch at the Microsoft support site. The Ansi value for the Euro-sign is 0128, so by holding down the Alt-key and then typing a 0, 1, 2 and 8 on the NumBlock, you should get a Euro-sign ( a character E with two dashes). Most programs use the key combination as shortcut for the Euro-sign. So probably you want to get a Euro-sign in the input of your Delphi program when you use this key-combination. When you try the normal solution with the OnKeyDown, you have a problem because you hear a disturbing beep, as the Alt+5 is a "non-functioning" shortcut. procedure TForm1.Memo1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); begin if (Shift = [ssAlt]) and (Key = Ord('5')) then Memo1.SelText:= ''; //Alt 0128 end; The Euro-sign after Memo1.SelText, is made in the Delphi code-editor by holding down the Alt-key and then typing 0, 1, 2 and 8 on the NumBlock. The solution is, not to use the OnKeyDown, but a Action from a ActionList, as a Action has a property Shortcut that you can use. You need Delphi 4 or more recent for this, as earlier versions have no ActionLists. This is the way you can do this: - Place a ActionList (from the tab Standard) on your Form. - Double-click the ActionList to get the Action Editor. - Click the button "New Action" to add Action1. - Type in the Object Inspector at the property Shortcut: Alt+5 (don't use the dropdown list). - Double-click de Event OnExecute. In the code you write: procedure TForm1.Action1Execute(Sender: TObject); begin Memo1.SelText:= ''; //Alt 0128 end; When you have a lot of input places on your Form, for instance a great number of Edits, you can use this code: procedure TForm1.Action1Execute(Sender: TObject); begin if (ActiveControl is TCustomEdit) then TCustomEdit(ActiveControl).SelText:= ''; //Alt 0128 end; When you use an Action, you can't use the Sender-object for determining in which input box the Euro-sign must be placed. That's why this code uses ActiveControl, the component focused. When it is a CustomEdit (the common parent of a Edit, Memo, RichEdit, etc.) the Euro-sign is placed. When it's not a CustomEdit then nothing happens, after all placing a Euro-sign in a Button etc. is of no use.