Subject Re: [IBO] Varchar with #0 char in it
Author Helen Borrie
At 02:45 AM 15/03/2008, you wrote:
>> I'm not sure if it is pertinent, but are you referring to the field
>> using .Value or .AsString? The .Value method does save extra code in
>> loops but the downside is it accesses the values as variants and
>> relies on Delphi to do the casting. That does increase the risk of
>> undesired effects such as (possibly) the encounter with the ascii-
>> zero causing the string to be interpreted as null-terminated. I
>> always use the casting methods where possible...
>
>here is my code:
>
>procedure TdmDatabase.SetEncryptedFieldText(Sender: TField; const
>Text: String);
>var
> lID: Integer;
>begin
> if Sender.DataSet.FieldByName('Encrypted').AsBoolean then
> begin
> lID := ...
> if not (Sender.Dataset.State in dsEditModes) then
> Sender.Dataset.Edit;
>
> Sender.AsString := GeneralFunctions.GetEncryptedData(Text, lID, ...);
> end;
>end;
>
>any other ideas?

You could try to disable casting entirely by using the AsRawString method instead of AsString.

Does your GetEncryptedData function return a quoted string? If not, you might like to try wrapping the expression inside QuotedStr, viz.

Sender.AsString := QuotedStr(GeneralFunctions.GetEncryptedData(Text, lID, ...));

Helen