Delphi Prismfor.NETを使用しています。メインフォームクラスのパブリックメソッドを別のwinformメソッドから呼び出す必要があります。それで、最近静的について学んだので、私はそれを私のプログラムで使用しました。静的またはクラスのwinformはうまく機能しますが、メソッドを静的またはクラスにすることは同じようには機能しないようです。
メインフォームクラスにupdateButtonsというメソッドがあります。ユーザーの操作に応じて、メインフォームのすべてのボタンとコントロールを更新します。このメソッドは、別のwinformメソッドから呼び出す必要があります。そこで、そのUpdateButtonsメソッドを静的またはクラスにしました。今、私は呼び出すメソッドを見ていますが、コンパイラーは好きではありません。「インスタンス参照なしでインスタンスメンバー(任意のコントロール)を呼び出すことはできません」というエラーが発生し続けます。
メソッドをクラスまたは静的にし、WinFormからコントロールにアクセスするにはどうすればよいですか?
静的メソッドまたはクラスメソッドを持つメインクラス:
MainForm = partial class(System.Windows.Forms.Form)
private
protected
method Dispose(disposing: Boolean); override;
public
class method updateButtons;
end;
updatebuttonの定義:
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;