Sort grid using memory table
<p>I want to sort a grid. I created a memory table and link it to the grid as the data source.I am inserting data to the memory table from a nxQuery object. For the sorting i have to add index as well to the memory table.</p>

<p>This is the index adding and inserting part which is in the form create event</p>

<pre><code>nxMemTable1.IndexDefs.Clear;
nxMemTable1.FieldDefs.Clear;

nxMemTable1.FieldDefs.Add('packpatientid', ftInteger, 0, False);
nxMemTable1.FieldDefs.Add('firstname', ftString, 10, False);
nxMemTable1.FieldDefs.Add('lastname', ftString, 10, False);
while not nxQuery1.EOF do
begin
  nxMemTable1.Append;
  nxMemTable1.FieldByName('packpatientid').AsInteger :=   nxQuery1packpatientid.AsInteger;
  nxMemTable1.FieldByName('firstname').AsString := nxQuery1firstname.AsString;
  nxMemTable1.FieldByName('lastname').AsString := nxQuery1lastname.AsString;
  nxMemTable1.Post;
end;
</code></pre>

<p>and this is the code that i am trying to sort the memory table</p>

<p><code>procedure TForm1.Button2Click(Sender: TObject);
begin
  nxMemTable1.IndexFieldNames := 'firstname';
end;</code></p>

<p>but this is not working. when i click the button it says "No index for field 'firstname'"</p>