Hi Guys, can anyone assist me with resolving incompatible types.

Hi Guys, can anyone assist me with resolving incompatible types.

I want to place a circle in my listviewitem but i keep getting this error. is there a quick fix?

 [DCC Error] TabbedTemplate.pas(197): E2010 Incompatible types: 'TFmxObject' and 'TListViewItem'

Comments

  1. w/o source code lines it would impossible...

    ReplyDelete
  2. Yes - please provide a source snippet so we can see what you're doing.

    ReplyDelete
  3. begin
      TThread.CreateAnonymousThread(
        procedure()
        var
          X: Integer;
          weburl3: string;
          item: TListViewItem;
          LImage4: TListItemObject;
          imagenew: TImage;
          memstream: TMemoryStream;
          circle1: Tcircle;

        begin

          for X := 0 to 40 do
            begin
              item := ListView1.Items.item[X];
              weburl3 := (item.Objects.FindObject('Data7') as TListItemText).Text;

              if weburl3 <> '' then
                begin



                  circle1 := circle1.Create(ListView1);
                  circle1.Parent := ListView1.Items.item[X];

                  circle1.fill.kind := TBrushKind.bkBitmap;
                  circle1.Stroke.kind := TBrushKind.bkNone;
                  circle1.fill.Bitmap.WrapMode := TWrapMode.wmTileOriginal;
                  circle1.ClipChildren := true;
                  circle1.Width := 100;
                  circle1.Height := 100;




                  begin
                    memstream := TMemoryStream.Create;
                    try

                      IdHTTP1.Get(weburl3, memstream);

                      memstream.position := 0;
                      TThread.Synchronize(TThread.CurrentThread,
                        procedure()
                        begin

                          memstream.SaveToFile(TPath.GetDocumentsPath + PathDelim +
                            'test.png');
                          circle1.fill.Bitmap.Bitmap.LoadFromFile
                            (TPath.GetDocumentsPath + PathDelim + 'test.png');
                          // Limage4.Bitmap.LoadFromFile(TPath.GetDocumentsPath + PathDelim + 'test.png');
                          DeleteFile(TPath.GetDocumentsPath + PathDelim +
                            'test.png');
                        end);

                    except
                      memstream.Free;
                      Exit;
                    end;
                  end;
                end;

            end;
          // ListView1.EndUpdate;
          // end;
          // end;

        end).start;
    end;

    ReplyDelete
  4. So basically, i'm creating a circle in the listview and then want to make the circles parent the listviewitem or var Item.

    ReplyDelete
  5. i've also tried creating the circle in the listviewitem but also get incompatible types :-(

    ReplyDelete
  6. Marek D 
    I think You can use
    circle1.fill.Bitmap.Bitmap.LoadFromStream(memstream);
    so You don't have to save to file, load from file and then delete the file.
    It's faster! :)

    ReplyDelete
  7. Thanks, i was doing it this way due to a bug in RAD studio. Any hints on how i can get my circle within the listviewitem?

    ReplyDelete
  8. I think it's wrong:
    circle1 := circle1.Create(ListView1);

    ReplyDelete
  9. What kind of error?
    LoadfFromFile uses LoadFromStream too

    ReplyDelete
  10. Nándor Kiss
     my problem is that i want to create circle1 within the var called item.
    When i do this, the error i get is [DCC Error] TabbedTemplate.pas(178): E2010 Incompatible types: 'TFmxObject' and 'TListViewItem'

    ReplyDelete
  11. so when i try the code circle1 := circle1.create(item);

    i get that error

    ReplyDelete
  12. Hi Simon, thanks for the reply,, my anonymous thread loads the Timage perfectly so i'm not sure why you would say its doomed to failure. it may not be correct but it achieves its purpose of not caused the application to hang.

    I will try your suggestion regarding the incompatible types issue. thanks again

    ReplyDelete
  13. What are you hoping to happen when you write:

        circle1 := circle1.Create(ListView1);

    You surely mean 

        circle1 := TCircle.Create(ListView1);

    ReplyDelete
  14. You also haven't told us which line of code has the error. Are you familiar with what E2010 means by the way?

    ReplyDelete
  15. Hi David, i have amended my code. the goal is to make my circle's parent the TListItemImage which is now called Limage. so after amending my code, i have
    lcircle := tcircle.create(listview1)
    lcircle.parent := Limage //here is where the problem lies

    E2010 Incompatible types: 'TFmxObject' and 'TlistItemImage' error appears on this line lcircle.parent := Limage

    under var, i have LImage: TListItemImage;

    Any clues on how i can get around this?

    ReplyDelete
  16. Marek D  I repeat my question. Do you understand what E2010 means? Do you appreciate then when you write x := y that there are certain constraints placed on the type of y? So, you understand why it is not possible to write someint := somestring? 

    Rather than tell you the answer, I'm trying to lead you towards you being able to work this out for yourself.

    ReplyDelete
  17. Hi David, Thanks for taking the time to assist me.I get the E2010 error message, they are not the same. so its like taking apples and making them oranges, it wont work. So tcircle is an FMXobject and Tlistitemimage is not an FMXobject. As you can see, i'm a noob :-(

    ReplyDelete
  18. Hi Simon, do you use inheritance to descend Tcircle from TlistitemImage?
    Sorry, this is now all way over the top of my head...sigh :-(

    ReplyDelete
  19. Thanks Simon, really appreciate your time, a silly question but my lcircle now no longer has any of its tcircle properties, such as lcircle.fill or lcircle.clipchildren.
    Is this the way its supposed to work?

    ReplyDelete

  20. endless questions...
    from both sides :)

    ReplyDelete
  21. "Your stuff here" means overriding the Render method of TListItemImage,
      perhaps you can try that out and report back?

      TCircleItemObject = class(TListItemImage)
      private
        Fill: TBrush;
      public
        constructor Create(const AOwner: TListItem); override;
        destructor Destroy; override;
        procedure Render(const Canvas: TCanvas; Selected: Boolean;
          SubPassNo: Integer); override;
      end;

    constructor TCircleItemObject.Create(const AOwner: TListItem);
    begin
      inherited;
      Fill := TBrush.Create(TBrushKind.bkSolid, claWhite);
    end;

    destructor TCircleItemObject.Destroy;
    begin
      Fill.Free;
      inherited;
    end;

    //start with copy of original Render method
    procedure TCircleItemObject.Render(const Canvas: TCanvas; Selected: Boolean; SubPassNo: Integer);
    //...
    var
      bmp: TBitmap;
      sr: TRectF;
      sm: T
    //...
    begin
      //refactor: use sm, sr, bmp istead of the private fields/methods
      sm := ScalingMode; //instead of FImageScalingMode
      sr := SrcRect; //instead of FSrcRect
      bmp := Bitmap; //instead of Bitmap := GetBitmap;
      //...
      Canvas.DrawBitmap(bmp, InpRect, DestRect, Opacity); //last line
      //then draw circle on top
      Canvas.DrawEllipse(DestRect, Opacity, Fill);
    end;

    usage:
    // c := TCircle.Create(ListView);
    // Parent := Item;
    lio := TCircleItemObject.Create(Item);
    Item.Objects.Add(lio);

    ReplyDelete
  22. Marek D I have not tested your code because your sample is not immediatly testable, but painting like TCircle should be possible inside the render method.

    constructor TCircleItemObject.Create(const AOwner: TListItem);
    begin
      inherited;
      Fill := TBrush.Create(TBrushKind.bkSolid, claWhite);
      Stroke := TStrokeBrush.Create(TBrushKind.bkSolid, claWhite);
    end;

    then do as TCircle does in the render method:

      Fill.Kind := TBrushKind.bkBitmap;
      Stroke.Kind := TBrushKind.bkNone;
      Fill.Bitmap.WrapMode := TWrapMode.wmTileOriginal;
      Canvas.FillEllipse(DestRect, Opacity, Fill);
      Canvas.DrawEllipse(DestRect, Opacity, Stroke);

    ReplyDelete
  23. This seemingly endless trail of comments is why questions like this belong on Stack Overflow.

    ReplyDelete

  24. I think our group should be renamed to
    "Delphi School (for Beginners, for newbies)"

    :)

    ReplyDelete
  25. Malcolm Kudra I think what you are referring to is the reaction that a bad question gets, with an asker that won't work to improve the question. In this case the asker is clearly very motivated to learn and eager to supply details. So it would work out well.

    ReplyDelete
  26. Malcolm Kudra I respectfully suggest that you don't understand how Stack Overflow works. Askers are given chance to improve. I don't know of a scenario where the chance to improve a question is denied.

    I don't know of any mechanism where individuals can "shut the discussion" down.

    ReplyDelete
  27. Malcolm Kudra Courtesy and civility are essential, no argument there.

    But I think that sometimes poor questions are asked. And get closed. That doesn't mean that discourse has been closed, or discussion shut down. It is just a way to make it clear to the asker that remedial action is needed to make the question fit the site.

    When questions are improved, they are, in my experience, reopened.

    I agree that having a question closed, and voted down is not a good feeling for the asker. I have plenty of memories of that happening to me and memories of those feelings keep me motivated to ask good questions.

    If there was no feedback on the quality of questions, I believe that a lot of askers would not put in the effort needed to ask a good question.

    It is true that some askers react badly to questions being closed and voted down. But equally a lot of askers respond well and try to take on board the criticism. In my view that is very positive.

    ReplyDelete
  28. Drawing circular images inside the Items of a ListView turned out to be not so easy and overriding the Render method of TListItemImage turns out to be uggly. Not sure at all if this is the recommended solution.

    I certainly would like to read about the recommended solution in Simon Stuart's blog. Given that Marek is quite new to quite a lot of things (Indy, Threading, ListView, Drawing, Mobile), he came up with an interesting test case - one which clearly could be improved, and rewritten to be testable in pieces.

    I am most interested in the threaded Indy Http Client on mobile example. Marek's overall task seems to be a nice one, with the drawing of a circular image only a bonus. So, if this example happens to be improved, please keep the downloading stuff in somewhere. :)

    ReplyDelete
  29. You are on the right track in making a round image, but you are not putting it in the ListViewItem correctly.
    In the samples that come with Delphi there are examples of listview with images.

    Put your images in the same way that they do.

    ReplyDelete
  30. This reminds me of when I switched from QBASIC to Turbo Pascal, spent a day trying to figure out how to assign a floating point number into an integer variable.

    This was way before I had internet, so no-one to ask, only the documentation. I was quite new to programming in general and my english was poor. I've had more fun days :)

    ReplyDelete

Post a Comment