向 TScrollBox 添加多个 TFrame 控件

发布于 2024-10-05 04:24:21 字数 680 浏览 0 评论 0原文

我正在用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

通知家属抬走 2024-10-12 04:24:21

我怀疑您希望滚动框中的多个框架最终位于彼此下方。您是否尝试过添加

cartRow.Align := alTop;

这会导致行自动彼此垂直对齐。

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.

听闻余生 2024-10-12 04:24:21

根据文档,您应该设置控件的父属性,而不是使用 InsertControl。因此代码应该是:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文