?
Solved

KeyDown event handler not working

Posted on 2007-07-22
11
Medium Priority
?
395 Views
Last Modified: 2010-04-05
Why am I getting this error?

Declaration of 'RichEdit3KeyDown' differs from previous declaration
and
Unsatisfied forward or external declaration 'TForm1.RichEdit3KeyDown

Its weird, all im trying to is put code in the RIchEdit3Keydown method handler

One thing I have noticed though is the procedure is always wordwrapped

so instead of

procedure TForm1.Edit28KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

it appears like this instead

procedure TForm1.Edit28KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);

might that make a difference?

Ben
0
Comment
Question by:Alpha_AI
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 19544054
no, that will make no difference

you will have a typo somewhere, that is all
Check the header declaration
(CTRL-SHIFT-UP or CTRL-SHIFT-DOWN to go between declaration and method)
and cut and paste the correct one

It may be because you had it declared as
RichEdit3KeyDown
but you know say Edit28KeyDown
0
 

Author Comment

by:Alpha_AI
ID: 19544129
that was just an example

the method declaration is

procedure TForm1.Edit28KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

and it appears like this in the code

procedure TForm1.Edit28KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

Its weird because I clear the code in the method handler and compile it doesnt compile
when i remove the component altogether it compiles
when i put the component editbox back on
click the keydown in events
and put a comment inside the code
and then compile it doesnt work. It comes up with that error

The KeyDown doesnt work but the KeyPress does..

Ben
0
 

Author Comment

by:Alpha_AI
ID: 19544141
the method declaration is:

    procedure Edit28KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

and it appears like this in the code

procedure TForm1.Edit28KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

looks like it should work but it comes up with the error and when i remove the editbox it works fine.

Ben
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Alpha_AI
ID: 19544149
but i tried a new application with just a editbox and then it works.
So is there a quick way to find the error in the original code.

some form of analysing technique included in Delphi 2007?

Ben
0
 
LVL 17

Expert Comment

by:TheRealLoki
ID: 19544435
make sure there is not already another function called Edit28KeyDown.

Just as a test, while it compiles (ie. your component is removed)
put a new control on the form with a different name.
create the header declaration and method manually, then hook up the event in the object inspector maually.
does that work?
0
 
LVL 21

Expert Comment

by:ziolko
ID: 19545417
check your uses clausule, maybe you have TShiftSate defined in two different units

ziolko.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 19545420
...like

interfcace
uses unit1
...
.Edit28KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState <- defined in unit1);

implementation
uses unit2

.Edit28KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState <- defined in unit2);

ziolko.
0
 
LVL 2

Expert Comment

by:bogdan_iuly
ID: 19545967
Hy!

Check to see if Delphi didn't get confused and end up by introducing the code between E and N from END. It happens very often in my D7. :)

Also, check the Object Inspector OnKeyDown value.

The declaration of the event should be before the private area. Check that too.

Or post the code here so that we can check it.

Here is the code for a basic application with a RichEdit, a OnKeyDown event handler.
---------------------------------

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    procedure RichEdit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.RichEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
//Do something
end;

end.

----------------------------------

object Form1: TForm1
  Left = 192
  Top = 114
  Width = 870
  Height = 640
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object RichEdit1: TRichEdit
    Left = 208
    Top = 128
    Width = 185
    Height = 89
    Lines.Strings = (
      'RichEdit1')
    TabOrder = 0
    OnKeyDown = RichEdit1KeyDown
  end
end
0
 
LVL 10

Assisted Solution

by:dinilud
dinilud earned 75 total points
ID: 19546439
Right click on TShiftState. Click on find target.
The declaration must be in "classes" unit.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 19623828
any progress?

ziolko.
0
 
LVL 13

Accepted Solution

by:
rfwoolf earned 300 total points
ID: 19805535
I think I know what happened...

If you declare it under "type" then you have to refer to it as TForm1.Edit28KeyDown, BUT, if you declare it under "var" then you can drop "TForm1" and just used Edit28KeyDown.

See the following I've typed up:

Your procedure declaration needs to come in the interface section of the form's unit (that's before the "implementation" section).
Then, if you put it down under 'type' as a type declaration it will be owned by the form, as in TForm1.MyProcedure
If however you put it under 'var' it will become a global procedure, as in just MyProcedure.
However, even though it may be "global", to use it from other units you would still have to put the unit in the other forms uses clause. e.g. If your procedure is in Unit 1, you would add Unit 1 to Unit 2's uses clause in order to use it.

---

About your problem, you need to go to the problem form, and do a search for the problem procedure - do this using Ctrl + F or using the menus. You will then have to take note of that procedure's declarations.

If you wish to make it global, declare it under the 'var' section just before 'implementation', and don't add the TForm1 to it, as follows. Declare it as follows:
procedure Edit28KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);

And once again, that header must be repeated exactly in your implementation section, as follows:

procedure Edit28KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
 ...
end;

---
HOPE THIS HELPS
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question