Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9158033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:09:25+00:00 2026-06-17T13:09:25+00:00

So I’m new to Delphi and I have a button and when it is

  • 0

So I’m new to Delphi and I have a button and when it is clicked it opens an OpenPictureDialog. I then want to create a popup box with that picture loaded into it. I’m not sure what the best approach to this would be?

I was thinking to make a new form on the button click event and then put the image into that, but I can’t figure out how to pass a TImage to a form constructor.

OpenPictureDialog1.Execute;
img.Picture.LoadFromFile(OpenPictureDialog1.FileName);
TForm2.Create(Application, img).Show;

Does anyone have a better idea of how to do this or a way to fix what I’m trying to do?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:09:26+00:00Added an answer on June 17, 2026 at 1:09 pm

    You better put the TImage component in your secondary form and pass a filename, for example, create a new constructor for your form like this:

    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;
    

    Then, you can create and show your form like this:

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Form2: TForm2;
    begin
      if OpenPictureDialog1.Execute then
      begin
        Form2 := TForm2.CreateWithImage(Self, OpenPictureDialog1.FileName);
        Form2.Show;
      end;
    end;
    

    Edit

    If you want to create the image at runtime, you can do it like this:

    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;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a small JavaScript validation script that validates inputs based on Regex. I
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.