I am trying to create a Previewlist
where i add an image and a remove button on top of it in TFramedVertScrollbar
with this code:
var
PreviewList: TFramedVertScrollBox;
i: integer;
...
procedure TDashboard.AddClick(Sender: TObject);
var
sImg: TImage;
sBtn: TButton;
sbit: TBitmap;
begin
sbit := TBitmap.Create;
try
with sbit do
begin
Width := Image1.Bitmap.Width;
Height := Image1.Bitmap.Height;
Assign(Image1.Bitmap);
end;
sImg := TImage.Create(PreviewList);
with sImg do
begin
Align := TAlignLayout.Top;
Position.X := i * Height;
Height := 60;
Margins.Bottom := 2;
Bitmap.Assign(sbit);
Parent := PreviewList;
WrapMode := TImageWrapMode.Stretch;
onClick := PreviewItemClick;
end;
sBtn := TButton.Create(sImg);
with sBtn do
begin
StyleLookup := 'listboxdeleteitem';
Position.X := sImg.Width - 25;
Position.Y := 5;
Width := 15;
Height := 15;
Text := 'X';
Parent := sImg;
onClick := PreviewItemClick;
end;
i := i + 1;
finally
sbit.Free;
Image1.Bitmap.Assign(nil);
end;
end;
The Creation of PreviewItem works but not removal as on removing the PreviewItem the SystemBar does not responds(ex can't move or close or click) or don't takes mouse events and i have to click on other components in the form to make it responsive again.
I tried to two version of PreviewListClick first is below:
begin
PreviewList.BeginUpdate;
Obj := TButton(Sender).Parent;
FreeAndNil(Obj);
PreviewList.EndUpdate;
end;
The Above Makes the SystemBar Not Responding so i did like this :
begin
PreviewList.BeginUpdate;
PreviewList.RemoveObject(TButton(Sender).Parent);
PreviewList.EndUpdate;
end;
SystemBar is responding in this case and item is removed but there is one problem, after clicking on the Remove button of PreviewItem the PreviewList items are not updated.
For Ex. if there are four item in list and if i remove second one then item is removed but the list is not updated as the position of second item is still kept. now the PreviewList Looks like this:
Item1->BlankSPace->Item2->Item3
how to correctly add and remove items ?
Removing Object from content worked fine
PreviewList.Content.RemoveObject(TButton(Sender).Parent);