Reputation: 22740
I'm doing a little offline shopping cart application here with Delphi and I'm stuck. I need to insert frame to scrollbox (act as shopping cart item row, where I can remove item, add quantity and so on) on product select from listview. But I can't add multiple frames there.
procedure TfrmMain.lvProductsSelectItem(Sender: TObject; Item: TListItem;
Selected: Boolean);
var
cartRow: TFrame1;
i: Integer;
count: Integer;
begin
cartRow := TFrame1.Create(nil);
cartRow.Edit1.Text := Item.Caption;
cartRowArr := TObjectList<TFrame1>.Create;
cartRowArr.Add(cartRow);
count := cartRowArr.Count;
for i := 0 to cartRowArr.Count - 1 do
begin
ScrollBox1.InsertControl(cartRowArr[i]);
end;
end;
It's always on frame there and can't get it right. If I select product I need to insert frame, if I select another product I need to insert antoher frame. If product that I select is alredy there, then raise quantity by one.
Any help appreciated!
Upvotes: 1
Views: 2858
Reputation: 133
Based on the docs, you should set the parent property of the control rather than use InsertControl. Therefore the code should be:
for i := 0 to cartRowArr.Count - 1 do
begin
cartRowArr[i].Parent := ScrollBox1;
end;
http://docwiki.embarcadero.com/Libraries/XE3/en/Vcl.Controls.TWinControl.InsertControl
Upvotes: 0
Reputation: 6529
I suspect that you want multiple frames in the scroll box to end up below each other. Have you tried adding
cartRow.Align := alTop;
This would cause the rows to automatically align themselves next to each other vertically.
Upvotes: 2