IROStrings and trailing carriage returns

Hi,

I’ve got a long-standing issue to which I’ve never found a solution. This is using Delphi against an MSSQL server with FireDAC.

Any text or varchar(max) type columns come through into my strongly-typed classes as properties of type IROStrings.

If I’m creating/updating a record and want to assign a simple text string to such a properties, I just use the Text property of the IROStrings wrapper.

Whilst this works, it always puts a CR/LF pair at the end of the string, which is obviously a hold-over from TStrings which has a habit of doing this.

Is there any way I can prevent this and assign a string to such a property without the CR/LF on the end?

After some experimentation, using FieldByName(‘field’).AsString appears to work.
I think I’ll add additional properties to my own derived interfaces and client rules classes to implement separate “FieldAsString” type properties for this purpose.

As this will be a little tedious to implement for every such field across my schemas, I could modify the code generator logic so these additional properties are automatically created when I generate my strongly typed classes.

Not sure whether that’s really recommended though as I’d have to re-implement my changes every time I upgraded DA.

Hi,

You can implement your changes and share them with us.
We’ll merge it to DA code.

Ok thanks, I may do that and send over the changes so you can see what you think.

Hi,

Check if TrimRight works in your case:
old:

procedure TCustomersDataTableRules.Remarks_OnChange(Sender: TObject);
begin
  if not f_DisableRemarksEvent and DataTable.Editing then DataTable.Fields[idx_CustomersRemarks].AsVariant := TStringList(Sender).Text;
end;

new:

procedure TCustomersDataTableRules.Remarks_OnChange(Sender: TObject);
begin
  if not f_DisableRemarksEvent and DataTable.Editing then DataTable.Fields[idx_CustomersRemarks].AsVariant := TrimRight(TStringList(Sender).Text);
end;

Without testing, I’d have thought that would work yes.

However, it would mean changing the auto-generated strongly-typed classes and such a change couldn’t be implemented in the codegen as it would change the existing behaviour and some users may well be depending on the trailing CRLF being added.

I actually did go through all my classes last night and create new AsString functions & properties in my own derived interfaces and classes which just use the AsString property of the underlying field directly.

This works perfectly and means I can access such fields either way.
When I get a chance I’ll try modifying the codegen to do the same automatically and submit it so you can see what you think.

This trailing CRLF problem is a long-standing ‘quirk’ of Delphi’s TStringList class and has always been very annoying.

Hi,

We can implement it via definition.
if correspondent definition is defined in DataAbstract_user.inc, it will cut trailing CRLF, otherwise it will use default behavior.

but you should conform that it works for you

Ok I will when I get a chance.

Even if it does, I’m unsure whether I’d prefer that method or the additional properties I’ve now defined.