#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    7
    Rep 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;
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    344
    Rep Power
    6
    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;
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    7
    Rep Power
    0
    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!

IMN logo majestic logo threadwatch logo seochat tools logo