Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > Apps

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 12-16-2009, 02:15 PM
GordC GordC is offline
Junior Member
 
Join Date: Jul 2009
Posts: 3
Default 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
Reply With Quote
  #2  
Old 12-16-2009, 03:58 PM
GeoWink GeoWink is offline
Senior Member
 
Join Date: Jan 2001
Posts: 885
Default

Are you displaying a jpeg? That would be

Image := TJPEGImage.Create;

Plus you need to put jpeg in the Uses clause.

George
Reply With Quote
  #3  
Old 12-16-2009, 09:16 PM
GordC GordC is offline
Junior Member
 
Join Date: Jul 2009
Posts: 3
Default

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);
...
Reply With Quote
  #4  
Old 12-17-2009, 04:59 PM
GordC GordC is offline
Junior Member
 
Join Date: Jul 2009
Posts: 3
Default

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
Reply With Quote
Reply

Tags
create, timage

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:05 AM.


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