Link to home
Start Free TrialLog in
Avatar of Alpha_AI
Alpha_AI

asked on

KeyDown event handler not working

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
Avatar of TheRealLoki
TheRealLoki
Flag of New Zealand image

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
Avatar of Alpha_AI
Alpha_AI

ASKER

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
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
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
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?
check your uses clausule, maybe you have TShiftSate defined in two different units

ziolko.
...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.
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
SOLUTION
Avatar of dinilud
dinilud
Flag of India 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
any progress?

ziolko.
ASKER CERTIFIED SOLUTION
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