2014-04-06 2 views
1

프로 시저를 다른 장치의 프로 시저와 연결하여 주 장치의 양식으로 작업 할 수 없습니다. 이 질문에 언급 된 바와 같이 인터페이스 아래에 프로 시저 선언을 추가하려고 시도했지만 How to run procedure from another unit?, 작동하지 않습니다. E2003 선언되지 않은 식별자 :이 [DCC 오류] Main.pas (27)를 도시 유지 'sayHi'여기서되는 코드 모두 단위 : Main.pas :델파이의 다른 장치에서 프로 시저가 선언되지 않은 식별자를 표시합니다.

unit Main; 

interface 

uses 
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, 
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Unit2; 

type 
    TForm1 = class(TForm) 
    procedure FormCreate(Sender: TObject); 
    private 
    { Private declarations } 
    public 
    { Public declarations } 
    end; 

var 
    Form1: TForm1; 

implementation 

{$R *.dfm} 

procedure TForm1.FormCreate(Sender: TObject); 
begin 
sayHi(); 
end; 

end. 

및 Unit2.pas

여기
program gl; 

uses 
    Vcl.Forms, 
    Main in 'Main.pas' {Form1}, 
    Unit2 in 'Unit2.pas'; 

{$R *.res} 

begin 
    Application.Initialize; 
    Application.MainFormOnTaskbar := True; 
    Application.CreateForm(TForm1, Form1); 
    Application.Run; 
end. 

가 main.dfm 파일입니다 :

여기

unit Unit2; 

interface uses Dialogs; 

procedure sayHi(); 

implementation 

procedure sayHi(); 
begin 
    ShowMessage('hi'); 
end; 

end. 
는 프로젝트에 대한 조선 민주주의 인민 공화국 파일입니다
object Form1: TForm1 
    Left = 0 
    Top = 0 
    Caption = 'Form1' 
    ClientHeight = 444 
    ClientWidth = 621 
    Color = clBtnFace 
    Font.Charset = DEFAULT_CHARSET 
    Font.Color = clWindowText 
    Font.Height = -11 
    Font.Name = 'Tahoma' 
    Font.Style = [] 
    OldCreateOrder = False 
    OnCreate = FormCreate 
    PixelsPerInch = 96 
    TextHeight = 13 
end 
+0

문제의 코드는 –

+1

입니다. 그러면 다른 문제가있을 수 있습니까? –

+2

실제로 진행되고있는 것을 재현하지 않습니다 –

답변

9

필자는 이전에 이것을 보았으며, 항상 다른 버전 인 "Unit2"가 먼저 발견되는 것과 관련이 있습니다.

기계에 Unit2.dcu 또는 pas가 두 개 이상 있습니다.
"SayHi"없이 발견되는 Unit2가 먼저 발견됩니다.

프로젝트와 Delphi Global 라이브러리 경로를 확인하십시오.

+3

... 유닛에 더 나은 이름을 부여하십시오 ;-) –

+0

완전히 동의하셨습니다! –

관련 문제