掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
クラス内の定義関数について (ID:36421)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
別のフォームのクラスのPublic内に定義した関数を呼び出す際、 誤ってそのフォームをCreateせずに呼び出したにもかかわらず、 正常に動作します。別途以下のようなサンプルを作成し、実行 してみましたが、やはり、正常に動作しています。 Createをしなくても呼び出せるのでしょうか? なお、Form2はプロジェクトオプションで、使用可能フォーム の方へ移動しています。 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; procedure FormShow(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Unit2; {$R *.dfm} procedure TForm1.FormShow(Sender: TObject); begin Form2:=nil; end; //本当は、Button1をClickする前に //Form2:=TForm2.Create(Application);とするつもり //だったのを、忘れてしまった。 procedure TForm1.Button1Click(Sender: TObject); var res : integer; begin res:=Form2.sub(100,200); Label1.Caption:=IntToStr(res); end; end. unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm2 = class(TForm) Label1: TLabel; private { Private declarations } public { Public declarations } function sub(a,b:integer):integer; end; var Form2: TForm2; implementation {$R *.dfm} function TForm2.sub(a,b:integer):integer; begin Result:=a+b; end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.