저는 Delphi Prism for .NET에서 작업하고 있습니다. 다른 winform 메서드에서 mainform 클래스의 public 메서드를 호출해야합니다. 그래서, 정적에 대해 최근에 배운 데, 나는 그것을 프로그램에서 사용했습니다. 정적 또는 클래스 winform 잘 작동하지만 메서드를 정적 또는 클래스 만들기 같은 작동하지 않는 것.Delphi Prism의 정적 또는 클래스 메서드
내 메인 폼 클래스에 updateButtons라는 메서드가 있습니다. 그것은 사용자의 행동에 따라 메인 폼의 모든 버튼과 컨트롤을 업데이트합니다. 이 메서드는 다른 winform 메서드에서 호출해야합니다. 그래서 저는 UpdateButtons 메서드를 정적 또는 클래스로 만들었습니다. 지금은 호출하는 메서드를 볼 수 있지만, 컴파일러는 좋아하지 않아. "인스턴스 참조없이 인스턴스 멤버 (모든 컨트롤)를 호출 할 수 없습니다."라는 오류가 계속 발생합니다.
메서드를 클래스 또는 정적으로 만들 수 있으며 어떻게 winform에서 컨트롤에 액세스 할 수 있습니까? 정적 또는 클래스 방법
Main 클래스 : UpdateButton의의
MainForm = partial class(System.Windows.Forms.Form)
private
protected
method Dispose(disposing: Boolean); override;
public
class method updateButtons;
end;
정의 :
class method MainForm.updateButtons;
begin
if SecurityEnabled then
LoginBtn.Enabled := true //All the lines where I call Buttons raise the error exception that I mentioned above.
else
begin
UnitBtn.Enabled := true;
SignalBtn.Enabled := true;
AlarmBtn.Enabled := true;
MakerBtn.Enabled := true;
TrendBtn.Enabled := true;
DxCommBtn.Enabled := (Scanning = false);
TxBtn.Enabled := true;
ControlBtn.Enabled := true;
PIDBtn.Enabled := true;
SystemBtn.Enabled := true;
WinListBox.Enabled := true;
WinBtn.Enabled := true;
ShutdownBtn.Enabled := true;
OptionBtn.Enabled := true;
LoginBtn.Enabled:=false;
end;
end;
사실,이 경우 dxCommWin.Scan에서 호출하고 싶다면 MainForm (self)에 대한 참조를 메서드의 두 번째 매개 변수로 전달하면됩니다.'dxCommWin.Scan (Scanning, self); 이 경우 메서드의 서명은'method dxCommWin.Scan (scanning : boolean; form : MainForm);과 같을 것이고 메서드 내에서 폼에 액세스 할 수 있습니다. 그게 내가 "양식에 대한 참조를 가져 오는 것"을 의미하는 것입니다. –
참. 나는 비슷한 코드를 구현할 계획을 가지고 있었지만, 내 솔루션에 대해 생각해 보았고 그 이후로는 dxCommWin.Scan을 호출 한 직후에이 메소드를 실행하는 것이 더 적합하다고 보였다. 고마워, 세바스챤. – ThN