Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   Apps (http://www.delphipages.com/forum/forumdisplay.php?f=8)
-   -   Creating a TImage instance (http://www.delphipages.com/forum/showthread.php?t=207894)

GordC 12-16-2009 02:15 PM

Creating a TImage instance
 
I have just taken Delphi3 out for a spin after a few years absence. In trying to create a TImage programatically, the following code does not work:-

var myImg: TImage;
begin
myImg:= TImage.Create;
.....
end.

I get the error message 'not enough actual parameters'. What is wrong here?
GordC

GeoWink 12-16-2009 03:58 PM

Are you displaying a jpeg? That would be

Image := TJPEGImage.Create;

Plus you need to put jpeg in the Uses clause.

George

GordC 12-16-2009 09:16 PM

Thanks George, No, I wasn't using a jpg graphic but I appreciate the info which is very useful.

I think the proper use of Create is to put the "owner"; in my case form1 like this:-
var myImg: TImage
...
myImg:= TImage.Create(form1);
...

GordC 12-17-2009 04:59 PM

Just to expand on creating images from bitmaps and jpgs, the following code may be of interest to members.
// Under global var declarations add the following
var Form1: Tform1; //already present
myBmp: TBitmap;
myImg: TImage; // add ExtCtrls to uses section
jImg: TJPEGImage; // add JPEG to uses section
------------------------------------------------------
// to create and display a bitmap file
myBmp:= TBitmap.Create;
myImg:= Timage.Create(form1); //note parameter 'form1'
myImg.parent:=self;
myBmp.LoadFromFile('path and name of file') //must be a bitmap file
myImg.picture.graphic:= myBmp; //displays picture
myBmp.free;
------------------------------------------------------
// to create and display a jpg file
jImg:= TJpegImage.Create;
myBmp:= TBitmap.Create; //
jImg.LoadFromFile('path and name of file'); //must be a jpg file
myBmp.Assign(jImg); //copy internally
myImg.picture.Bitmap:=myBmp; //display file
myBmp.free;
------------------------------------------------------
You can put this code into a FormCreate or a ButtonClick event handler.
Also you might want to use the OpenDialog to select the file(s).
Note the subtle differences between 'Creates'.
Gord C


All times are GMT. The time now is 04:23 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.