【问题标题】:How to implement a FireMonkey TStringGrid Sort function: TFMXObjectSortCompare?如何实现 FireMonkey TStringGrid 排序功能:TFMXObjectSortCompare?
【发布时间】:2012-09-16 12:40:36
【问题描述】:
type
  TMyForm= class(TForm)
    sg       : TStringGrid;
    imgSortIt: TImage;
    ...
    procedure imgSortItClick(Sender: TObject);
  private
    { Private declarations }
//    sortIt: TFMXObjectSortCompare;
    function sortIt(item1, item2: TFmxObject): Integer;
  public
    { Public declarations }
  end;

var
  frm: TMyForm;

implementation

{$R *.fmx}

procedure TMyForm.imgSortItClick(Sender: TObject);
begin
  sg.Sort(???);
...

嗨,

我知道如何切换行以手动对网格进行排序...

但是作为TSTringGrid 有一个过程Sort,我尝试将它与我自己的比较函数与this procedure 一起使用...

我应该如何构造类型/函数以使其工作? 实际上,我明白了:

  • E2009 Incompatible types: 'regular procedure and method pointer'
  • 它使用如下声明的函数进行编译:sortIt: TFMXObjectSortCompare; 但如何实现代码按我的意愿排序?

感谢您的帮助。

【问题讨论】:

    标签: delphi sorting delphi-xe2 implementation firemonkey


    【解决方案1】:

    您正在查看XE3 documentation,据此TFmxObjectSortCompare 声明为:

    reference to function(Right, Left: TFmxObject): Integer;
    

    不幸的是,在XE2 中,TFmxObjectSortCompare 是这样声明的:

    function(item1, item2: TFmxObject): Integer;
    

    因此,您需要提供常规程序。也就是说,sortIt 不允许作为类的方法,而必须是普通的旧函数:

    function sortIt(item1, item2: TFmxObject): Integer;
    begin
      Result := ...
    end;
    

    我怀疑这是 XE2 FMX 代码中的设计错误。排序比较功能比reference to灵活得多,这大概就是它被更改的原因。

    【讨论】:

    • 感谢您提供详细信息。顺便说一句,TFmxObjectTStringColumns...所以对行进行排序不是很有用;o) 我会手动进行...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-25
    • 2019-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多