0
votes

I made a very simple testproject in Delphi 10.2 using FMX. The setup is simple :

  • TGrid that is binded to a TClientDataSet (done in the designer).
  • button that allows the user to open an XML file

This all works fine and the TGrid is populated with all records from the XML File. The XML file is created by another TClientDataSet from an older project.

Now for the problem.
When I move a column to another position all the data is messed up. I do this by just holding down the mouse on a column and than drag it a few columns to the right.
At first it looks fine, but when you start scrolling vertical, it seems that the data is not in the correct columns anymore.
I have the feeling that it only corrects the data in the visual part of the grid, and as soon as you start scrolling the data is not in the correct columns anymore.

Is this a known bug or is there something wrong with my project.
As I said before, there is absolutely no code in this project all is done in the designer. (except for the clientdataset1.LoadFromFile offcourse)

2
When it comes to FMX, it is important to indicate the Delphi version correctly due to the many changes during the past years. In your text you speak about XE 10 , which doesn't exist. In the tags you have selected delphi-xe which did not have FMX. So please, edit your q and make necessary corrections.Tom Brunberg
@TomBrunberg I dont have that delphi here so I cannot check right now which version. But it was XE10 what I saw when starting it. So I am confused here.GuidoG
@TomBrunberg I called my colleage whith this delphi it seems to be XE10.2GuidoG
I corrected it for you, there's no 'XE' anymore. Regarding your issue, I was able to reproduce it, but I have no fix and sofar did not find anything on Embarcaderos issue list.Tom Brunberg
Take a look at this question from a few days ago: stackoverflow.com/q/43418528/2292722 The problem is the same, but the answer is unnecessarily complicated by the saving/loading of column order. To Get and Set data, the cure is to assign the Tag property to the original column and use that as reference instead of the ACol parameter.Tom Brunberg

2 Answers

1
votes

You can try populate your data manually (Grid: TGrid; CDS: TClientDataSet):

procedure TForm1.FormCreate(Sender: TObject);
var
  I: Integer;
  Col: TColumn;
begin
  CDS.Active := True;
  for I := 0 to CDS.FieldDefs.Count - 1 do begin
    Col := TColumn.Create(Grid);
    Grid.AddObject(Col);
    Col.Header := CDS.FieldDefs[I].Name;
    Col.Tag := I;
  end;
  Grid.RowCount := CDS.RecordCount;
end;

procedure TForm1.GridGetValue(Sender: TObject; const ACol, ARow: Integer; var Value: TValue);
begin
  CDS.First;
  CDS.MoveBy(ARow);
  Value := CDS.Fields[ACol].Text;
end;

And after this you can use my solution for columns: stackoverflow.com/q/43418528/2292722

1
votes

This fixed it for me. I just move the fields that where moved in the grid also in the ClientDataSet and thus far it seems to work.

procedure TForm1.Grid1ColumnMoved(Column: TColumn; FromIndex, ToIndex: Integer);
var
  FieldFrom : string;
  FieldTo   : string;
begin
  FieldFrom := Grid1.ColumnByIndex(FromIndex).Header;
  FieldTo   := Grid1.ColumnByIndex(ToIndex).Header;

  ClientDataSet1.FieldByName(FieldFrom).Index := FromIndex;
  ClientDataSet1.FieldByName(FieldTo).Index   := ToIndex;
end;

But I just wish there was a better way of knowing from the TColumn which fieldname is involved. Seems like the most significant information is missing from this class.