掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
複数のユニットを使用するには? (ID:15171)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
話が変な方向にいってるので、おまけ usesに追加せず参照する方法。 --unit2.pas unit Unit2; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs; type TForm2 = class(TForm) private { Private 宣言 } FHoge: Integer; public { Public 宣言 } published property Hoge: Integer read FHoge write FHoge; end; implementation {$R *.dfm} initialization RegisterClass(TForm2); end. -- unit1.pas unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, TypInfo; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private 宣言 } FForm2: TForm; public { Public 宣言 } end; implementation {$R *.dfm} var localForm: TForm1; procedure TForm1.Button1Click(Sender: TObject); var PropInfo: PPropInfo; i: Integer; begin if FForm2 = nil then begin FForm2 := TForm(GetClass('TForm2').NewInstance); FForm2.Create(Self); FForm2.Show; end; PropInfo := GetPropInfo(FForm2, 'Hoge'); if PropInfo = nil then Exit; i := GetOrdProp(FForm2, PropInfo); SetOrdProp(FForm2, PropInfo, i+1); ShowMessage(IntToStr(GetOrdProp(FForm2, PropInfo))); end; initialization Application.Initialize; Application.CreateForm(TForm1, localForm); Application.Run; end. -- project1.dpr program Project1; uses Forms, Unit2 in 'Unit2.pas' {Form2}, Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin end.
←解決時は質問者本人がここをチェックしてください。
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.