简体   繁体   English

firemonkey (FMX) 中的 IndexFieldNames 问题

[英]Problems with IndexFieldNames in firemonkey (FMX)

The problem occurs only in firemonkey.该问题仅在firemonkey中出现。 With VCL it works perfectly.使用 VCL 可以完美运行。

I have a dataset (of any type) connected to a grid (of any type) when clicking on the title of the column this must be ordered by the corresponding field.单击列标题时,我有一个连接到网格(任何类型)的数据集(任何类型),这必须按相应字段排序。

For VCL对于 VCL

procedure TForm2.DBGrid1TitleClick(Column: TColumn);
begin
  qrySec.IndexFieldNames := Column.FieldName;
end;

For FMX对于 FMX

procedure TManFarmaQry.StringGrid1HeaderClick(Column: TColumn);
begin
     
case Column.Index of
          0:
            if mtblMedica.IndexFieldNames = 'Field1' then
              mtblMedica.IndexFieldNames := 'Field1' + ':D'
            else
              mtblMedica.IndexFieldNames := 'Field1';
    
          1:
            if mtblMedica.IndexFieldNames = 'Field2' then
              mtblMedica.IndexFieldNames := 'Field2' + ':D'
            else
              mtblMedica.IndexFieldNames := 'Field2';
          2:
            if mtblMedica.IndexFieldNames = 'Field3' then
              mtblMedica.IndexFieldNames := 'Field3' + ':D'
            else
              mtblMedica.IndexFieldNames := 'Field3';
        end;
end;

In the case of FMX, a rearrangement of the registers is observed but it does not correspond to anything.在 FMX 的情况下,可以观察到寄存器的重新排列,但它不对应任何内容。 Leaving everything untidy.让一切不整洁。

I think that since Firedac is used in both cases, the problem is not there.我认为由于在这两种情况下都使用了 Firedac,所以问题不存在。 Then there is a synchronization problem in the bind.然后是bind中的同步问题。

Delphi 10.3.3 Delphi 10.3.3

Hoping that the solution I found will serve someone else, here I leave it.希望我找到的解决方案能为其他人服务,我把它留在这里。

procedure TManFarmaQry.StringGrid1HeaderClick(Column: TColumn);
begin
  // Putting things practical    
      if mtblMedica.IndexFieldNames = LinkGridToDataSourceBindSourceDB1.Columns[Column.Index].MemberName then
        mtblMedica.IndexFieldNames := LinkGridToDataSourceBindSourceDB1.Columns[Column.Index].MemberName + ':D'
      else
        mtblMedica.IndexFieldNames := LinkGridToDataSourceBindSourceDB1.Columns[Column.Index].MemberName;

    
    // Here is the solution. Refresh datasource
        LinkGridToDataSourceBindSourceDB1.Active := False;
        LinkGridToDataSourceBindSourceDB1.Active := True;

end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM