Is there a way to automatically remove all leading and trailing spaces in text fields

In a Delphi application that uses TADODataSet components to access an Access database, is there a way to remove leading and trailing spaces from text fields when writing to disk? or perhaps while retrieving data, but without changing all my queries.

I mean in the ADO engine, without coding myself, using Trim() in BeforePost for each table.

+4
source share
3 answers

With all the restrictions you set ... No

My advice would be to encode the BeforePost event only once and associate all tables with the same beforepost event.

In the object object

 Table1.BeforePost:= TrimFieldsBeforePost; Table2.BeforePost:= TrimFieldsBeforePost; .... 

In your code

 procedure TMyForm.TrimFieldsBeforePost(DataSet: TDataSet); var i: integer; begin i:= 0; while i < Dataset.Fields.Count do begin if (Dataset.Fields[i].DataType in [ftString, FtMemo, ftFixedChar, ftWideString,FtVariant, ftFixedWideChar, ftWideMemo]) then begin Dataset.Fields[i].AsString:= Trim(Dataset.Fields[i].AsString); end; Inc(i); end; end; 
+6
source

Create your own child component TADODataSet ( TJuanADODataSet ) and include the behavior you want in the BeforePost event. Refactor to make all existing TADODataSet in TJuanADODataSet s.

+5
source

I haven't touched Access in years, but are there auto-cropping features in text fields?

0
source