向 TScrollBox 添加多个 TFrame 控件
我正在用 Delphi 做一个小的离线购物车应用程序,但我被困住了。我需要在从列表视图中选择产品时将框架插入到滚动框(充当购物车项目行,我可以在其中删除项目、添加数量等)。但我无法在那里添加多个框架。
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;
它总是在框架上,无法正确处理。如果我选择产品,我需要插入框架,如果我选择其他产品,我需要插入另一个框架。如果我选择的产品已经存在,则将数量增加一。
任何帮助表示赞赏!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑您希望滚动框中的多个框架最终位于彼此下方。您是否尝试过添加
这会导致行自动彼此垂直对齐。
I suspect that you want multiple frames in the scroll box to end up below each other. Have you tried adding
This would cause the rows to automatically align themselves next to each other vertically.
根据文档,您应该设置控件的父属性,而不是使用 InsertControl。因此代码应该是:
http://docwiki.embarcadero.com /Libraries/XE3/en/Vcl.Controls.TWinControl.InsertControl
Based on the docs, you should set the parent property of the control rather than use InsertControl. Therefore the code should be:
http://docwiki.embarcadero.com/Libraries/XE3/en/Vcl.Controls.TWinControl.InsertControl