Menu

TableItem.ImageName: a question and a request

GJB
2013-08-09
2013-08-13
  • GJB

    GJB - 2013-08-09

    Hello,

    i have one question regarding the imagename of tableitem. Can I only use the PNG format or also JPG? If I use a JPG it does not show.

    My request would be that you expose the Bitmap of the image so that I can load it directly. I am using a database and the image is read to a stream which I use to create a bitmap. And it would be lovely to assign the bitmap directly to the image

    Kind regards
    Gernot

     
  • Babak Yaghoobi

    Babak Yaghoobi - 2013-08-10

    Hi Gernot

    Yes you can use jpg and tableview can be show it.
    for adding bitmap property to tableview please add a request to Tickets section

    regards

     

    Last edit: Babak Yaghoobi 2013-08-10
  • GJB

    GJB - 2013-08-10

    Hi Babak,

    unfortunately jpg does not work. I use the following code

    it.ImageName := GetHomePath + PathDelim + 'Documents' + PathDelim + 'about1.jpg';

    with it being a TableItem. If I use a png it get displayed, if I use a jpg I cannot display it

    Should I open a ticket?

    regards

     
  • Babak Yaghoobi

    Babak Yaghoobi - 2013-08-10

    Hi Gernot

    See this sample!

    Remember, first deploy image then build and run.

     

    Last edit: Babak Yaghoobi 2013-08-10
  • GJB

    GJB - 2013-08-11

    Hi Babbak,

    thanks for the sample. Since I can only assign a path for the image I try to create the image dynamically from the database and then load it via the filename. It looks like something goes wrong during the extraction and I need to figure that out first.

    Thanks for your continued great support
    Gernot

     
  • GJB

    GJB - 2013-08-11

    I used your sample and tried to create dynamically a TableItem with the same image. I can create the TableItem but the image does not get displayed. I attach the modified sample (the code for the dynamic item is in the test button)

    I look forward to your ideas.

    Kind regard
    Gernot

     
    • Babak Yaghoobi

      Babak Yaghoobi - 2013-08-11

      Hi, Gernot

      use relative path instead of absolute path:

      with DPFTV_Files.Sections.Items[0].TableItems.Add do
      begin
      ItemText.Text := 'Image Test';
      //ImageName := GetHomePath + PathDelim + 'Documents' + PathDelim + 'DPF.jpg';
      ImageName := '/Documents/DPF.jpg';
      end;

      Tell me If you're forced to use an absolute path. i

       
  • GJB

    GJB - 2013-08-11

    Thanks Babak

    I was not aware that a relative path would make a difference. I will try to implement it in my program

     
  • GJB

    GJB - 2013-08-11

    Hi Babak,

    I change the test button to copy JPG to another filename, test for the file and to load it into the TableItem. Unfortunately the file exists but does not get displayed. The code is as follows:

    var
    ms: TMemoryStream;
    bmp: TBitmap;
    begin
    ms := TMemoryStream.Create;
    ms.LoadFromFile(GetHomePath + PathDelim + 'Documents' + PathDelim + 'DPF.jpg');
    ms.Position := 0;
    bmp := TBitmap.CreateFromStream(ms);
    bmp.SaveToFile(GetHomePath + PathDelim + 'Documents' + PathDelim + 'dpf_test.jpg');
    if FileExists(GetHomePath + PathDelim + 'Documents' + PathDelim + 'dpf_test.jpg')
    then ShowMessage('File exists');
    with DPFTV_Files.Sections.Items[0].TableItems.Add do
    begin
    ItemText.Text := 'Image Test';
    ImageName := '/StartUp/Documents/dpf_test.jpg';
    end;
    DPFTV_Files.RefreshNeeded;
    bmp.Free;
    ms.Free;
    end;

    Would you kindly have a look at it?

    Kind regards
    Gernot

     
    • Babak Yaghoobi

      Babak Yaghoobi - 2013-08-11

      Hi, Gernot

      Use this:

      var
      ms : TMemoryStream;
      bmp: TBitmap;
      begin
      ms := TMemoryStream.Create;
      ms.LoadFromFile( GetAppFolder + '/Documents/DPF.jpg' );
      ms.Position := 0;
      bmp := TBitmap.CreateFromStream( ms );
      bmp.SaveToFile( GetAppFolder + 'Documents/dpf_test.jpg' );
      if FileExists( GetAppFolder + 'Documents/dpf_test.jpg' ) then
      ShowMessage( 'File exists' );
      with DPFTV_Files.Sections.Items[0].TableItems.Add do
      begin
      ItemText.Text := 'Image Test';
      ImageName := '/Documents/dpf_test.jpg';
      end;
      DPFTV_Files.RefreshNeeded;
      bmp.Free;
      ms.Free;
      end;

       
  • GJB

    GJB - 2013-08-11

    Dear Babak,

    many thanks. I am nearly there. Now I have the following problem that I always get the first copy linked to the tableitem.

    Try the following: use a global var i := integer and a second image and modify the code like that:

    Inc(i);
    ms := TMemoryStream.Create;
    if i mod 2 = 0 then
    ms.LoadFromFile( GetAppFolder + 'StartUp/Documents/DPF.jpg')
    else ms.LoadFromFile( GetAppFolder + 'StartUp/Documents/test.jpg');

    By pressing the test button you should get alternating images but the result is always the second image

    Kind regards
    Gernot

     
    • Babak Yaghoobi

      Babak Yaghoobi - 2013-08-11

      Hi, Gernot

      please give me a full code for test

      thanks

       
  • GJB

    GJB - 2013-08-11

    here it comes - thanks for your patience
    Gernot

     
    • Babak Yaghoobi

      Babak Yaghoobi - 2013-08-11

      Hi Gernot

      dont use same filename for table rows, must be use unique filename for each row,
      when you call refreshneeded table recreate and want to load all visible rows images,

      Use like this :

      var
      ms : TMemoryStream;
      bmp: TBitmap;
      begin
      Inc( i );
      ms := TMemoryStream.Create;
      if i mod 2 = 0 then
      ms.LoadFromFile( GetAppFolder + 'StartUp/Documents/DPF.jpg' )
      else
      ms.LoadFromFile( GetAppFolder + 'StartUp/Documents/test.jpg' );
      ms.Position := 0;
      bmp := TBitmap.CreateFromStream( ms );
      bmp.SaveToFile( GetAppFolder + 'StartUp/Documents/dpf_test' + inttostr( i ) + '.jpg' );
      with DPFTV_Files.Sections.Items[0].TableItems.Add do
      begin
      ItemText.Text := 'Image Test';
      Height := 120;
      ImageName := '/StartUp/Documents/dpf_test' + inttostr( i ) + '.jpg';
      end;
      DPFTV_Files.RefreshNeeded;
      bmp.Free;
      ms.Free;
      end;

       
  • Babak Yaghoobi

    Babak Yaghoobi - 2013-08-11

    another recommendation:
    use unique name only for unique images,
    e.g: in this your sample you have 2 image and if you want to load this 2 images in many rows
    you need to save only 2 unique image file

     
  • GJB

    GJB - 2013-08-11

    This is the reason why I would love to see the bitmap exposed. That way I could assign a bitmap to each row.

    What I need to achieve is:
    -Item in TableView1 is clicked
    -Image from database is saved to the same file (overwriting the previous file)
    -tableview2 is completely cleared (including the previous image link)
    -new section is created
    -new item1 with an image from the above saved file is loaded
    -tableview2 is displayed

    This works for the first click on Tableview1. Afterwards I always get the image from the first save as I cannot clear it from the system. Is there any way to remove everything from tableview2 so that a new image can be loaded (even though it has the same filename).

    Actually I really need only one image but that gets save to the same file before creating the new tableview

     

    Last edit: GJB 2013-08-11
  • Babak Yaghoobi

    Babak Yaghoobi - 2013-08-12

    Hi, Gernot

    For clear table use: DPFTV_Files.ClearAll();
    If you want to have a Bitmap in the TableItem make a Ticket.

    Kind Regards

     
  • GJB

    GJB - 2013-08-12

    Hi Babak,

    I can live without the ticket if this works with loading the image. However if I I need unique filenames every time I would end up with a lot of wasted space.

    unfortunately ClearAll is not the solution. I attach a modified sample to show what I want to achieve. If you click on an item in DPFTV_Files (not the test button) I copy the image, call ClearAll for DPFTV_Videos and rebuild DPFTV_Videos. This should give me alternating images. But only the itemtext changes, not the image.

    That is basically what I want to achieve - I only need one image (which varies, as it is retrieved from a database) in the 2nd level

    Kind regards

     
    • Babak Yaghoobi

      Babak Yaghoobi - 2013-08-12

      Hi, Gernot

      I you want to use same file name for alternating images you will see this problem,
      Dont forget iOS TableView use a buffering mechanisms for showing rows only visible rows created and used when you scroll down or up all rows released and new rows created.
      therefore, if you want to use same file name after a scroll down then scroll up all your row images may be show incorrect images!

      So, you have only 2 way :

      1) use unique image file name,
      2) i make a bitmap property in TableItem

      regards

       
  • Babak Yaghoobi

    Babak Yaghoobi - 2013-08-12

    Hi, Gernot

    Download last source from [code] section, and install it, then see attachment demo

    regards

     

    Related

    Code: code

  • GJB

    GJB - 2013-08-12

    Dear Babak

    I bow my head in admiration. This is an absolut perfect solution and it works like a charm.

    Many many thanks and keep going

    Kindest regards
    Gernot

     
  • Babak Yaghoobi

    Babak Yaghoobi - 2013-08-13

    Hi, Gernot

    I'm glad I could help

    Good luck

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.