Link to home
Start Free TrialLog in
Avatar of Manuel Lopez-Michelone
Manuel Lopez-MicheloneFlag for Mexico

asked on

Simulating keyboard actions with delphi

Hi experts!

I have this problem: In a program I am working on, I have some custom Listbox with items. I can click on one item and the item will be selected... So I use the information of the item and process it. As soon I process this item, I want to simulate the action of doubleclick to go to the next item. Because this is a custom made listbox, I don't have access to indexitems. So I guess is a good idea to simulate the click (or double click) over the next item.

Is there a way to do this thru delphi 7?

regards
Manuel Lopez (lopem)
ASKER CERTIFIED SOLUTION
Avatar of 2266180
2266180
Flag of United States of America 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
you are developping a Delphi application
and by stating  "Because this is a custom made listbox"
what do you mean ?

surely it is a Delphi component with events ?
and if so it should have properties too
maybe like FocusedIndex or ItemIndex
i couldn't guess why these properties are unavailable
but if so, it is a poor component
how do you know what item was clicked or dblclicked ?

there should be an event too : OnDblClick
if nothing is assigned then the code is in the component ?

and maybe you can subclass so you have acess to all properties (including private and protected) with

type
  TMagicListbox = class(TYourListbox)
  end;

and when you use the TYourListbox cast it to the new type:
TMagicListbox(YourListbox)
and you will have all properties

TMagicListbox(YourListbox).ItemIndex := 0; // for the first element

TMagicListbox(YourListbox).ItemIndex := TMagicListbox(YourListbox).ItemIndex +1;
to focus the next element

>>  you can subclass so you have acess to all properties (including private and protected)

that is half true. with subclassing yuo get access to protected stuff only. not private :) in order to get access to private stuff, you need to declare the subclassing calss in teh same unit as the subclassed class. (I say stuff so to include: properties, members and methods)
>>ciuly
i stand corrected about that stuff :D

Avatar of Manuel Lopez-Michelone

ASKER

Hi, Geertz,

I am using some components to build some chess application. They are very well written but some of the components have few peculiar behaviour, for instance, the custom Listbox I was talking about (a way to load a PGN file to a listbox. A PGN file is a collection of chess games in some format called Portable Game Notation).

Of course teh component has OnDoubleclick, OnClick, etc. methods but they don't work as usual. For instance, if you want to see a chess game, there is not enough just to go to PGN1.Items[PGN1.ItemIndex]. For some reason you have to push the [enter]  key over the item selected or double click on it.  If you dont do this, you can't have access to a particular chess game. If I put the onDoubleClick method in my procedure, it always gives to me some sort of error saying the parameters are incorrect. Of course, I am doing something wrong but I couldn't figure out was wrong. To make things worst, the help file is in german  so I can actually understand some of it using altavista online translator.

I found that the simple way to accomplish my task and to get rid of the error was just to insert some [enter] key thru programming or simulate a doubleclick over the item I selected.  I know this is not the best thing to do but I was really fed up with the error...

When I read your remark I was thinking how it is possible to have some simple problems with these components? In any case, I actually solved my problems but I know I have to dig a little bit more around the chess components I am using.

best regards and thanks for your comments.

Manuel López (lopem)