2012-01-01 58 views
2

錯誤:對實際的和正式變種參數類型必須是相同的如何解決命名和範圍衝突?

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(米); 一個簡單的問題,爲什麼?

我知道類型有問題,但所有類型都是類似的,無處不在的字節,奇怪的 對我來說我無法運行一個程序。

回答

5

的問題是,doKeyPressTForm1的方法(從TWinControl繼承),所以當你寫一個doKeyPress方法TForm1裏面的編譯器要使用TForm1.doKeyPress而不是本地功能。類作用域比本地作用域更近。

可能的解決方案包括:

  • 重命名的本地功能,避免衝突。
  • 使用完全限定名稱unAutoKeypress.doKeyPress

在我看來,前者是更好的解決方案。

+0

謝謝。現在好了! – 2012-01-01 19:10:48

7

TFormTWinControl繼承和有一個稱爲在TWinControl聲明DoKeyPress方法,該方法是在ButtonClick事件內部編譯器的電流範圍。

+0

我能爲事件做些什麼是有效的,如何區分它們? – 2012-01-01 19:00:48