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'
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'
w/o source code lines it would impossible...
ReplyDeleteYes - please provide a source snippet so we can see what you're doing.
ReplyDeletebegin
ReplyDeleteTThread.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;
So basically, i'm creating a circle in the listview and then want to make the circles parent the listviewitem or var Item.
ReplyDeletei've also tried creating the circle in the listviewitem but also get incompatible types :-(
ReplyDeleteMarek D
ReplyDeleteI 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! :)
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?
ReplyDeleteI think it's wrong:
ReplyDeletecircle1 := circle1.Create(ListView1);
What kind of error?
ReplyDeleteLoadfFromFile uses LoadFromStream too
Nándor Kiss
ReplyDeletemy 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'
so when i try the code circle1 := circle1.create(item);
ReplyDeletei get that error
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.
ReplyDeleteI will try your suggestion regarding the incompatible types issue. thanks again
What are you hoping to happen when you write:
ReplyDeletecircle1 := circle1.Create(ListView1);
You surely mean
circle1 := TCircle.Create(ListView1);
Noted, thanks for the heads up.
ReplyDeleteYou also haven't told us which line of code has the error. Are you familiar with what E2010 means by the way?
ReplyDeletemultiacc? lol
ReplyDeleteHi 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
ReplyDeletelcircle := 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?
Nándor Kiss
ReplyDeleteyep :-)
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?
ReplyDeleteRather than tell you the answer, I'm trying to lead you towards you being able to work this out for yourself.
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 :-(
ReplyDeleteHi Simon, do you use inheritance to descend Tcircle from TlistitemImage?
ReplyDeleteSorry, this is now all way over the top of my head...sigh :-(
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.
ReplyDeleteIs this the way its supposed to work?
ReplyDeleteendless questions...
from both sides :)
"Your stuff here" means overriding the Render method of TListItemImage,
ReplyDeleteperhaps 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);
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.
ReplyDeleteconstructor 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);
This seemingly endless trail of comments is why questions like this belong on Stack Overflow.
ReplyDelete
ReplyDeleteI think our group should be renamed to
"Delphi School (for Beginners, for newbies)"
:)
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.
ReplyDeleteMalcolm 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.
ReplyDeleteI don't know of any mechanism where individuals can "shut the discussion" down.
Malcolm Kudra Courtesy and civility are essential, no argument there.
ReplyDeleteBut 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.
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.
ReplyDeleteI 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. :)
You are on the right track in making a round image, but you are not putting it in the ListViewItem correctly.
ReplyDeleteIn the samples that come with Delphi there are examples of listview with images.
Put your images in the same way that they do.
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.
ReplyDeleteThis 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 :)