I have a 3 character fkLookup field sat_site in a table. I'm using TAdsTable table component. When I filter out records in my grid on a field sat_site, grid does not show any records. With ShowMessage() I check the value of field sat_site which shows blanks or boxes in the message pop-up. Following is my source code:

procedure TfrmMain.tblSaturdayFilterRecord(DataSet: TDataSet; var Accept: Boolean);
begin
  if frmSatOffDays.Edit7.Text <> '' then
    begin
      ShowMessage(tblSaturday.FieldByName('SAT_SITE').AsString); // checking value
      if (DataSet['sat_month']= frmSatOffDays.Edit9.Text) and (tblSaturday.FieldByName('SAT_SITE').AsString = frmSatOffDays.Edit7.Text) then
        begin
          Accept := True;
        end
      else
        begin
          Accept := False;
        end;
    end
  else
    begin
      if tblSaturday.FieldByName('sat_month').AsString = frmSatOffDays.Edit9.Text then
        begin
          Accept := True;
        end
      else
        begin
          Accept := False;
        end;
    end;
end;

Following are the properties of the field sat_site:

Alignment           taLeftJustify
AutoGenerateValue   arNone
DisplayLabel        SAT_SITE
DisplayWidth        3
FieldKind           fkLookup
FieldName           SAT_SITE
Index               3
KeyFields           SAT_HONO
LookupCache         False
LookupDataSet       tblMasterFileDBF
LookupKeyFields     HONO
LookupResultField   tblSaturdaySAT_SITE
ReadOnly            False
Required            False
Size                3
Transliterate       True
Visible             True

I have tried replacing field name of SAT_SITE in the event by tblSaturdaySAT_SITE.AsString but the result is the same. Can anyone help me?

Thanks and best regards.

Edited 1 Year Ago by pritaeas: Moved to Delphi.

I would like to add here that the data in dbGrid shows up perfectly but when comparing for filtering data, the field sat_site shows funny characters in the event OnFilterRecord.

Hi,

I have solved my problem.

First thing was that the SAT_SITE was showing funny characters. This was solved by using function AnsiString(SAT_SITE) which then started showing the right contents of the fkLookup field value.

Secondly I was trying to filter out the records based on the SAT_SITE fkLookup field which failed. I leant from certain blogs that the event OnRecordFilter is executed before the field value is written to the grid. Therefore, I changed the statement in the OnRecordFilter from comparing the SAT_SITE value against the user selected field value for filtering records with comparing the user selected value against the field of the table from where the SAT_SITE field is extracted.

Although now the filter works perfectly but the grid becomes slow.

This question has already been answered. Start a new discussion instead.