TImage コンポーネントをセカンダリ フォームに配置し、ファイル名を渡すことをお勧めします。たとえば、次のようにフォームの新しいコンストラクタを作成します。
type
TForm2 = class(TForm)
Image1: TImage;
private
public
constructor CreateWithImage(AOwner: TComponent; AImgPath: string);
end;
...
implementation
...
constructor TForm2.CreateWithImage(AOwner: TComponent; AImgPath: string);
begin
Create(AOwner);
Image1.Picture.LoadFromFile(AImgPath);
end;
次に、次のようにフォームを作成して表示できます。
procedure TForm1.Button1Click(Sender: TObject);
var
Form2: TForm2;
begin
if OpenPictureDialog1.Execute then
begin
Form2 := TForm2.CreateWithImage(Self, OpenPictureDialog1.FileName);
Form2.Show;
end;
end;
編集
実行時にイメージを作成する場合は、次のようにします。
type
TForm2 = class(TForm)
private
FImage: TImage; //this is now in the private section,
//and not the default (published)
public
constructor CreateWithImage(AOwner: TComponent; AImgPath: string);
end;
...
implementation
...
constructor TForm2.CreateWithImage(AOwner: TComponent; AImgPath: string);
begin
Create(AOwner);
FImage := TImage.Create(Self);
FImage.Parent := Self;
FImage.Align := alClient;
FImage.Picture.LoadFromFile(AImgPath);
end;