Delphi 如何修复命名和范围冲突?

Delphi 如何修复命名和范围冲突?,delphi,scope,naming,conflict,Delphi,Scope,Naming,Conflict,错误:实际和形式var参数的类型必须相同 unit unAutoKeypress; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Button1: TButton; Memo2: TMemo; p

错误:实际和形式var参数的类型必须相同

unit unAutoKeypress;

interface

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

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    Memo2: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure SimulateKeyDown(Key:byte);
begin
keybd_event(Key,0,0,0);
end;

procedure SimulateKeyUp(Key:byte);
begin
keybd_event(Key,0,KEYEVENTF_KEYUP,0);
end;

procedure doKeyPress(var KeyValue:byte);
begin
 SimulateKeyDown(KeyValue);
 SimulateKeyUp(KeyValue);
end;



procedure TForm1.Button1Click(Sender: TObject);
const test = 'merry Christmas!';
var m: byte;
begin
Memo2.SetFocus();
m:=$13;
doKeyPress(m); // THIS IS WHERE ERROR
end;

end.
doKeyPress(m)功能中始终存在错误; 一个简单的问题,为什么

我知道类型有问题,但所有类型都是相似的,到处都是字节,奇怪
对我来说,我不能运行程序。

TForm
是从
TWinControl
继承的,有一个名为
DoKeyPress
的方法在
TWinControl
中声明,它在
按钮单击事件中的编译器的当前范围内

问题在于
doKeyPress
TForm1
的方法(继承自
TWinControl
),因此当您在
TForm1
方法中编写
doKeyPress
时,编译器希望使用
TForm1.doKeyPress
而不是本地函数。类范围比局部函数范围更近

可能的解决办法包括:

  • 重命名本地函数以避免冲突
  • 使用完全限定名,
    unAutoKeypress.doKeyPress

在我看来,前者是一个更好的解决方案。

我能为这些事件做些什么是有效的,如何将它们分开?