In a Delphi application which uses TADODataSet components to access to an Access database, there is any way to delete leading and trailing spaces from text fields when record is written to disk? or perhaps when retrieving the data, but without modifying all my queries.
I mean in ADO engine, without coding myself using Trim()
in BeforePost
on every table.
With all the limitations you've put up... No
My advice would be to code a BeforePost event just once and link all tables to the same beforepost event.
In the objectinspector
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With