Results 1 to 6 of 6

Thread: Lazarus TWinControl TImage

  1. #1

    Lazarus TWinControl TImage

    Compiler/IDE: Lazarus
    Libraries/API: LCL

    To change the caption of labels i'm using:
    [pascal]
    for i:=1 to 10 do
    formname.ControlByName('tlabelname'+inttostr(i)).c aption:='';
    [/pascal]

    I tryed to use the same way to load image
    [pascal]
    for i:=1 to 10 do
    formname.ControlByName('timagename'+inttostr(i)).p icture.LoadFromFile('file.bmp');
    [/pascal]

    I looked in the LCL reference and saw that thers no method like this by useing ControlByName.

    Does someone has any idea how to load image from file to list of Timages by their names?

  2. #2

    Lazarus TWinControl TImage

    FindComponent I think it's called
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  3. #3

    Lazarus TWinControl TImage

    thanks

    It's bringing back TComponent - wich means the TImage class.
    But still... I can't use it. I think findcomponent it's for the management of the components hirarchy. not for editing them.


    meanwhile I used case of. but it's just doing the code ugly(i'll need to do lots of changeing if i'll want to add more TImages)

  4. #4

    Lazarus TWinControl TImage

    I haven't tried Lazarus but shouldn't something like this work?

    Code:
    var Component: TComponent;
    begin
      Component := FindComponent('Image1');
    
      if Assigned(Component) then
        TImage(Component).Canvas.FillRect(TImage(Component).ClientRect);

  5. #5

    Lazarus TWinControl TImage

    You managed to change the captions because all controls have this property. Not all controls have a 'Picture' member, so you need to type-cast the control to a TImage, first. Even though you already know that it's a TImage, the compiler can only assume (unless you tell it otherwise) that it's just a regular control object.

    Code:
    for i:=1 to 10 do
    TImage(formname.ControlByName('timagename'+inttostr(i))).Picture.LoadFromFile('file.bmp');
    Game-Dev Journal: http://skirmish.dreamhosters.com/devlog/

  6. #6

    Lazarus TWinControl TImage

    Quote Originally Posted by HopeDagger
    You managed to change the captions because all controls have this property. Not all controls have a 'Picture' member, so you need to type-cast the control to a TImage, first. Even though you already know that it's a TImage, the compiler can only assume (unless you tell it otherwise) that it's just a regular control object.

    Code:
    for i:=1 to 10 do
    TImage(formname.ControlByName('timagename'+inttostr(i))).Picture.LoadFromFile('file.bmp');
    Thanks
    It works^_^

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •