[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 484
  • Last Modified:

No picture in a TPicture

HI,
I am having a problem using TPicture. Strangely, recently I wrote a program in Delphi7 that uses TPictures, and it works fine. I must have forgotten a critical step and don't see it in my other program, Here is the simplest example;
Start a new MDI project.
Put a TPicture, small, about 2 inches wide, and a button on the form.
Add "JPEG" to USES
Toggle stretch to true for the TImage
Make an On-Click event for the button
Write this line:
Image1.Picture.LoadFromFile('C:\Images\DSC00053.jpg');
In this case this is a valid path to an existing .jpg file, about 600K. I have also tried this with a small .bmp.
I run the program and click on the button. No picture. I can't even see the empty picture. I tried it last night on Delphi7/W2K. I usually am using Delphi 2010 on a W7 machine. There is no picture on either computer. I tried adding a few lines after the load from picture such as Image1.Refresh, redraw. Nothing.

For the final part of the experiment I select the file for the design time picture property. It displays on the form, and at run time. When I click the button noting happens. The design time image still displays.

I must be forgetting some simple step. What is it ?
0
ChLa
Asked:
ChLa
  • 2
1 Solution
 
Ephraim WangoyaCommented:

You are not missing any steps, this should be working with no problem

Unless some other code is clearing it or the image is not valid
0
 
ChLaAuthor Commented:
It doesn't make sense since I repeated it on another computer with different Delphi and OS, and since i am starting with a new project. The same image displays if I assign it at design time, so must be valid. And I have tried other simple jpeg and bmp images.
0
 
systanCommented:
When dealing with MDIForm, use ".Realign;" after image changed.
procedure TForm1.btn1Click(Sender: TObject);
begin
 img1.Picture.LoadFromFile('c:\windows\winnt.bmp');
 Form1.Realign;
end;

Open in new window

0
 
ChLaAuthor Commented:
That did it. MainForm.Realign.
Thank you.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now