Here's an example of setting an expression index. You'll have to place a TBufDataset, datasource, and dbgrid on your form and hook them up appropriately, then add OnCreate and OnDestroy handlers for your form as follows. Of course in a proper program your datasets would be put in a separate datamodule.
unit mainExpressionIdx;
{$mode objfpc}{$H+}
interface
uses
Forms, DBGrids, DbCtrls, db, BufDataset, Classes;
type
{ TForm1 }
TForm1 = class(TForm)
dataNames: TBufDataset;
dsNames: TDatasource;
grdNames: TDBGrid;
navNames: TDBNavigator;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
dataNames.FieldDefs.Add('Forename',ftString,15,True);
dataNames.FieldDefs.Add('Surname',ftString,15,True);
dataNames.FieldDefs.Add('ID',ftAutoInc,0,True);
dataNames.CreateDataset;
dataNames.IndexDefs.Add('ForenameSurnameExprIdx','Surname;Forename',[ixCaseInsensitive,ixUnique]);
dataNames.Open;
dataNames.AppendRecord(['Arthur','Gates',0]);
dataNames.AppendRecord(['Arthur','Jones',0]);
dataNames.AppendRecord(['Bill','Gates',0]);
dataNames.AppendRecord(['Emily','Gates',0]);
dataNames.AppendRecord(['Tim','Avery',0]);
dataNames.AppendRecord(['Sven','Obama',0]);
dataNames.IndexFieldNames:='Surname;Forename';
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
dataNames.Close;
end;
end.