【问题标题】:Weird behavior in delphi xe CustomListBoxItemdelphi xe CustomListBoxItem中的奇怪行为
【发布时间】:2014-07-03 19:00:38
【问题描述】:

我在 Delphi xe6 中创建了一个自定义 ListBoxItem,(基于 @MikeSutton 在这篇文章中的回答 What control should I use to create this UI in Delphi Firemonkey

我有 2 个TNumberBox 和 2 个TLabels。 这是我的自定义列表框项

TListBoxItemMatchBet = class(TListBoxItem)
private
            ....
            //some other methods and properties
    fLeftValue: integer;
    procedure setLeftValue(const Value: integer);
    procedure setLeftValueStyle();
    procedure LeftValueChange(Sender: Tobject);

protected
    procedure ApplyStyle; override;
published
    property Text: string read fText write setText;
    property LeftValue: integer read fLeftValue write setLeftValue;
    property RightValue: integer read fRightValue write setRightValue;

end;

procedure TListBoxItemMatchBet.setLeftValue(const Value: integer);
begin
    fLeftValue := Value;
    setLeftValueStyle();

end;

procedure TListBoxItemMatchBet.setLeftValueStyle;
var
    O: TFMXObject;
begin
    O := FindStyleResource('nmbLeft'); // StyleName of the item
    if O is TNumberBox then
    begin
        TNumberBox(O).ValueType := TNumValueType.Integer;
        TNumberBox(O).Value := fLeftValue;
        TNumberBox(O).OnChange := LeftValueChange;
    end;

end;
procedure TListBoxItemMatchBet.ApplyStyle;
begin
    inherited;
    setTextStyle();
    setLeftValueStyle();
    setRightValueStyle();
end;

procedure TListBoxItemMatchBet.LeftValueChange(Sender: Tobject);
begin
    fLeftValue := round((Sender as TNumberBox).Value);
end;

一切都很好,除非我的列表框中有很多(大约 20 个)项目并且我向上滚动,当我向下滚动时,数字框的值将更改为其他记录(例如,当我回滚项目时值为 50它的值将更改为其他值,例如 10 和 50 将转到其他列表框项)。

此行为在 Android 和 Iphone 模拟器上。

这是一些屏幕截图。

设置值(右上角)


向上滚动


向下滚动

价值观消失了

【问题讨论】:

  • @MikeSutton 有什么想法吗?

标签: delphi delphi-xe listboxitem delphi-xe6


【解决方案1】:

经过几天的努力,我找到了解决方案:

只需在样式书中创建所需的样式并将项目添加到 ListBoxItem 中

注意从TListBoxItem实例化

Itemx := TListBoxItem.Create(self);
Itemx.StyleLookup := 'listBoxItemNumericEditable';
Itemx.Text := 'A Title';

这就是诀窍

Itemx.StylesData['nmbLeft.Value'] := 50;

你甚至可以像这样添加事件处理程序

  Itemx.StylesData['nmbLeft.OnChange'] := TValue.From<TNotifyEvent>(DoNumberChange); 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-19
    • 1970-01-01
    • 2014-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多