Delphi: setting the OnGetText event handler for dynamic query fields

I want to configure my own procedure for the OnGetText event of fields in a dynamic request

My procedure is as follows:

procedure TMainFrm.MyFieldGetText(Sender: TField; var Text: String; DisplayText: Boolean); begin ... end; 
  • "... Captions" are the constants of the String array

I installed an event handler in the OnAfterOpen event for ADOQuery:

 procedure TImportFrm.ADOQueryAfterOpen(DataSet: TDataSet); var I : Integer; begin for I := 0 to ADOQuery.FieldCount - 1 do ADOQuery.Fields[I].OnGetText := MainFrm.MyFieldGetText; end; 

But after opening ADOQuery there is no text to display, it looks like the value of Text is empty!

It doesn't seem to matter what my procedure does, because when I set up an empty procedure (without code), the text does not appear too

what's wrong?

thanks...

+5
source share
2 answers

Try the following:

 procedure TMainFrm.MyFieldGetText(Sender: TField; var Text: String; DisplayText: Boolean); begin if Sender.FieldName = 'XX' then begin Text := .... String(Sender.Value);// ( or Text := Sender.AsString); end; if Sender.FieldName = 'YY' then begin Text := .... String(Sender.Value);// ( or Text := Sender.AsString); end; ... end; 
+3
source

Thank you all

The problem was that I should mention all Text situations and should use Sender.value instead of the text on the right side ! I changed my procedure to this problem and solved the problem:

 procedure TMainFrm.MyFieldGetText(Sender: TField; var Text: String; DisplayText: Boolean); begin if Sender.AsVariant = Null then Exit; Text := Sender.AsString; if MatchStr(Sender.FieldName, BooleanFieldNames) then Text := BooleanCaptions[Sender.AsInteger]; if Sender.FieldName = 'BNStatus' then Text := BNStatusCaptions[Sender.AsInteger]; if MatchStr(Sender.FieldName, ['FStatus', 'LStatus', 'FirstStatus']) then Text := FLStatusCaptions[Sender.AsInteger]; if Sender.FieldName = 'PayType' then Text := PayTypeCaptions[Sender.AsInteger]; if Sender.FieldName = 'BGType' then Text := BGTypeCaptions[Sender.AsInteger]; if Sender.FieldName = 'Updated' then Text := UpdatedCaptions[Sender.AsInteger]; if Sender.FieldName = 'DieUser' then Text := DieUserCaptions[Sender.AsInteger]; if Sender.FieldName = 'LiveUser' then Text := LiveUserCaptions[Sender.AsInteger]; if Sender.FieldName = 'NVStatus' then Text := NVStatusCaptions[Sender.AsInteger]; if Sender.FieldName = 'BSGender' then Text := BSGenderCaptions[Sender.AsInteger]; if Sender.FieldName = 'BSMType' then Text := BSMTypeCaptions[Sender.AsInteger]; end; 

Thanks again...

+1
source

All Articles