Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 26th, 2012, 02:17 PM
newsoul newsoul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 newsoul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 49 m 37 sec
Reputation Power: 0
Create objects automatically

I'm trying to create some TImage objects automatically and load the picture from a directory so as not to stack my .dfl files with thousands of lines of hexadecimal code for each "picture data".

Can you tell me what's wrong with my procedure?

procedure tform1.setimage;
var x:TImage;

begin
x:=x.timage.create(self);
x.parent:=form1;
x.resizable:=true;
x.top:=0;x.left:=0;
x.picture.loadfromfile('1.jpg') {which is placed where the unit is}
x.show;
end;

Reply With Quote
  #2  
Old October 26th, 2012, 06:36 PM
majlumbo majlumbo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 255 majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 2 m 15 sec
Reputation Power: 5
Make sure JPEG is in your uses clause

Code:
Procedure TForm1.SetImage;
var
   X: TImage;
   Jpg: TJpegImage;
begin
   X := TImage.create(self);
   X.Parent := Self;//Do not use Form1 always use self
   X.Top := 0;
   X.Left := 0;
   Jpg := TJpegImage.Create;
   try
      Jpg.LoadFromFile('1.jpg');
      X.Width := Jpg.Width;
      X.Height := Jpg.Height;
      X.Picture.Graphic:=Jpg;
   finally
      Jpg.Free;
   end;
   X.Show;
end;

Reply With Quote
  #3  
Old October 27th, 2012, 04:42 AM
newsoul newsoul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 7 newsoul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 49 m 37 sec
Reputation Power: 0
Quote:
Originally Posted by majlumbo
Make sure JPEG is in your uses clause

Code:
Procedure TForm1.SetImage;
var
   X: TImage;
   Jpg: TJpegImage;
begin
   X := TImage.create(self);
   X.Parent := Self;//Do not use Form1 always use self
   X.Top := 0;
   X.Left := 0;
   Jpg := TJpegImage.Create;
   try
      Jpg.LoadFromFile('1.jpg');
      X.Width := Jpg.Width;
      X.Height := Jpg.Height;
      X.Picture.Graphic:=Jpg;
   finally
      Jpg.Free;
   end;
   X.Show;
end;


It worked. Thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Create objects automatically

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap