2017-10-20 69 views
0

我在Delphi中有兩個不同的單元。 第一個單元有一個名爲ApplyUpdates的過程,它所做的全部都是運行查詢。嘗試從另一個單元調用過程時發生訪問衝突

我需要從另一個單元訪問此過程中,當我這樣做,我得到的,說:「訪問衝突」」的錯誤消息

在第一單元的步驟:

procedure TForm1.ApplyUpdates (var AppType: string); 
begin 
    qryApplyUpdates.ParamByName('type').DataType := ftString; 
    qryApplyUpdates.ParamByName('type').ParamType := ptInput; 
    qryApplyUpdates.ParamByName('type').AsString := AppType; 
    qryApplyUpdates.ExecSQL; 
end; 

從第二單元I調用此過程爲:

var 
    UserForm: TForm1; 
begin 
    UserForm.ApplyUpdates (AppType); 
end; 

當調試它,它在程序的第一行右停止

我的問題是:我做錯了什麼,我無法從第一個單元訪問此過程?

回答

2

如果窗體自動創建,不要使用本地變量都:

// The default declared variable for an autocreated form is the classname without the prefix 
Form1.ApplyUpdates(AppType); 

如果表格沒有自動創建,你必須創建窗體,然後才能使用它。

var 
    UserForm: TForm1; 
begin 
    UserForm := TForm1.Create(nil); 
    try 
    UserForm.ApplyUpdates(AppType); 
    finally 
    UserForm.Free; 
    end; 
end; 
+0

太棒了!謝謝,我會在幾分鐘內接受你的回答 –

相關問題