Board index » delphi » How to use the hotkey control?

How to use the hotkey control?

I want to get the keypress(s) from The hotkey control to an edit box
or similiar. I can press any combination in the Hotkey control and see
the value eg: Control - X  but how do I pass that to the edit box?
cheers
 

Re:How to use the hotkey control?


In article <378a55de.37361...@news.spacestar.net>, sleip...@northernnet.com

Quote
(Grey Daegmorgan) writes:
>I have spent the past two days going over and over this problem
>without finding a workable answer.  I've fallen into a rut and become
>quite frustrated, since I keep thinking up the same, previously
>dismissed solutions over and over.  Thus I'm hoping some kind soul can
>help me out.

>Here's the setup:
>Think of a simple foreign-language dictionary with a wordlist (in the
>language) and a definition list (in english).  I have the foreign
>words displayed in ComboBox1 and the definitions displayed in
>ComboBox2.  Both lists are read out of a text file and into the
>program.

>The comboboxes are currently synchronized (ie -- when you choose a
>word in CB1, the correct meaning is displayed in CB2; and when you
>choose a definition in CB2, the correct word is displayed in CB1),
>however they are not alphabetized.

>What I've been unsuccessfully trying to do is have both lists
>alphabetized *and keep the synchronization of the two comboboxes.
>The difficulty arises in that there are occasionally words or
>definitions which match one another (for example, two different words
>which mean "harmony").  My solution to the problem could not
>differentiate between harmony and harmony, however (if you see what
>I'm getting at).

You have to keep the synchronisation over two sortings - one for the english
and one for the foreign language. This necessitates allocating some unique
number to each word/ translation pair and then re-associating the words after
sorting. Do it this way :-

1 Have two stringlists (unsorted) one with the english and the other with the
corresponding foreign translation. ie stringlist1.string[3] will be the
translation of stringlist2.string[3] & vice-versa

2 Put the index of each stringlist.string in the stringlist.object of that
string. ie stringlist.object[3] will have the value 3 in it.

3 Sort the stringlists

4 Assign the stringlists to the combobox.items.

5 (Now's the clever bit) Go through the english stringlist (by i), get the
object, look for it in the foreign stringlist (using Foreign.IndexOfObject())
let this result be k. Put k in the English.Object[i] and i in the
Foreign.Object[k]. We have to look in the stringlists and change the comboboxes
because otherwise we would confuse our searching by finding an object we had
changed.

6 Now in the ComboBox's OnClick set the other box's ItemIndex to the value in
the clicked one's Object.

Voila ! - but I haven't yet solved the two words the same - but they will
appear and get appropriate translations.

I put english and german numbers in a text file with a tab between and used
this code :-

procedure TForm1.Button1Click(Sender: TObject);
var
  SLEnglish, SLGerman : TStringList;
  i, k : integer;
  jPtr : pointer;
begin
  {get english numbers into stringlist together with unsorted positions}
  SLEnglish := TStringList.Create;
  with SLEnglish do begin
    LoadFromFile('E:\temp\Numbers.txt');
    {text file has "english word tab german word"}
    for i := 0 to Count - 1 do begin
      {remove the german word}
      Strings[i] := Copy(Strings[i], 1, Pos(#9, Strings[i]) - 1);
      {note the unsorted position - really an Id for the word}
      Objects[i] := pointer(i);
    end; {for i := 0 to Count - 1}
    {sort the stringlist}
    Sorted := true;
    Sorted := false;
    {assign to the combobox}
    ComboBox1.Items.Assign(SLEnglish);
  end; {with SLEnglish}
  {get german numbers into stringlist together with unsorted positions}
  SLGerman := TStringList.Create;
  with SLGerman do begin
    LoadFromFile('E:\temp\Numbers.txt');
    {remove the english word}
    for i := 0 to Count - 1 do begin
      Strings[i] := Copy(Strings[i], Pos(#9, Strings[i]) + 1,
Length(Strings[i]));
      Objects[i] := pointer(i);
    end; {for i := 0 to Count - 1}
    Sorted := true;
    Sorted := false;
    ComboBox2.Items.Assign(SLGerman);
  end;{with SLGerman}
  {now update the cross reference - because we are changing the
   item we're looking for we have to change the combobox object
   value while doing the search in the stringlists}
  for i := 0 to SLEnglish.Count - 1 do begin
    jPtr := SLEnglish.Objects[i];
    k := SLGerman.IndexOfObject(jPtr);
    ComboBox1.Items.Objects[i] := pointer(k);
    ComboBox2.Items.Objects[k] := pointer(i);
  end; {for i := 0 to SLEnglish.Count}
  SLEnglish.Free;
  SLGerman.Free;
end;

procedure TForm1.ComboBox1Click(Sender: TObject);
begin
  with ComboBox1 do
    ComboBox2.ItemIndex := integer(Items.Objects[ItemIndex]);
end;

procedure TForm1.ComboBox2Click(Sender: TObject);
begin
  with ComboBox2 do
    ComboBox1.ItemIndex := integer(Items.Objects[ItemIndex]);
end;

Alan Lloyd
alangll...@aol.com

Re:How to use the hotkey control?


Quote
On Tue, 13 Jul 1999 05:44:41 GMT, awh...@southwest.com.au (Al) wrote:
>I want to get the keypress(s) from The hotkey control to an edit box
>or similiar. I can press any combination in the Hotkey control and see
>the value eg: Control - X  but how do I pass that to the edit box?
>cheers

Wow looks like the experts are stumped then.
Do I get a prize?

Re:How to use the hotkey control?


Al schrieb in Nachricht <378dbc60.16223...@news.southwest.com.au>...

Quote
>On Tue, 13 Jul 1999 05:44:41 GMT, awh...@southwest.com.au (Al) wrote:

>>I want to get the keypress(s) from The hotkey control to an edit box
>>or similiar. I can press any combination in the Hotkey control and see
>>the value eg: Control - X  but how do I pass that to the edit box?
>>cheers

>Wow looks like the experts are stumped then.
>Do I get a prize?

I can understand the experts even if I'm none.
I read your post a time ago but I didn't understand your problem.
Do you want to display the HotKey in your edit box when the key is pressed,
what what would be exactly the same thing that the HotKey component does
itself?
Why then?
Or are you looking for a property that contains the text.
This is called HotKey.
And the type of this property is TShortCut.
And you can use ShortCutToText to convert this shortcut into a string.

Is it this you are looking for?
Matthias.

Other Threads