Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 503
Juanmi Sosso Avatar asked Dec 21 '22 08:12

Juanmi Sosso


1 Answers

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;
like image 61
Johan Avatar answered Dec 24 '22 00:12

Johan