#1 2017-01-23 20:17:46

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 337

Exception in SynMustache using nested expression helpers

Hi @ab, I try using nested expression helpers and I get an exception when last expression helper finalize. I can reproduce the issue with a modified version of sample "23 - Javascript Tests".

https://drive.google.com/file/d/0Bx7LPc … sp=sharing

Can you see the problem ? I need use this feature.

Thanks in advance.

Esteban.


Esteban

Offline

#2 2017-01-25 14:57:48

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 337

Re: Exception in SynMustache using nested expression helpers

I cannot solve the problem yet, but I found a strange behavior. I changed the function FromBase64 and ToBase64.

...
class procedure TMainForm.FromBase64(const Value: variant; out result: variant);
var
  lValue, lResp: RawByteString;
begin
  VariantToRawByteString(Value, lValue);
  lResp := SynCommons.Base64ToBin(lValue);
  RawByteStringToVariant(lResp, result);
end;
...
class procedure TMainForm.ToBase64(const Value: variant; out result: variant);
var
  lValue, lResp: RawByteString;
begin
  VariantToRawByteString(Value, lValue);
  lResp := SynCommons.BinToBase64(lValue);
  RawByteStringToVariant(lResp, result);
end;

but the error continue, if I hardcoded in ToBase64 the result variable this works

...
class procedure TMainForm.FromBase64(const Value: variant; out result: variant);
var
  lValue, lResp: RawByteString;
begin
  VariantToRawByteString(Value, lValue);
  lResp := SynCommons.Base64ToBin(lValue);
  RawByteStringToVariant(lResp, result);
end;
...
class procedure TMainForm.ToBase64(const Value: variant; out result: variant);
var
  lValue, lResp: RawByteString;
begin
  VariantToRawByteString(Value, lValue);
  lResp := SynCommons.BinToBase64(lValue);
//  RawByteStringToVariant(lResp, result);
  result := 'dGV4dCBlbmNvZGVkIHdpdGggYmFzZTY0IHVzaW5nIGJpbnRvYmFzZTY0IGZ1bmN0aW9u';
end;

or if I hardcode the lValue variable in FromBase64, too this works

...
class procedure TMainForm.FromBase64(const Value: variant; out result: variant);
var
  lValue, lResp: RawByteString;
begin
  lValue := 'dGV4dCBlbmNvZGVkIHdpdGggYmFzZTY0IHVzaW5nIGJpbnRvYmFzZTY0IGZ1bmN0aW9u';
//  VariantToRawByteString(Value, lValue);
  lResp := SynCommons.Base64ToBin(lValue);
  RawByteStringToVariant(lResp, result);
end;
...
class procedure TMainForm.ToBase64(const Value: variant; out result: variant);
var
  lValue, lResp: RawByteString;
begin
  VariantToRawByteString(Value, lValue);
  lResp := SynCommons.BinToBase64(lValue);
  RawByteStringToVariant(lResp, result);
end;

I am very confused.

Any help is appreciated.

Esteban.


Esteban

Offline

#3 2017-01-25 15:00:42

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 337

Re: Exception in SynMustache using nested expression helpers

I forgot to mention, in Delphi XE 10.1 Berlin the exception "Invalid Pointer Operation" is raised, in Delphi 7 the application it freezes.

Thanks.

Esteban.


Esteban

Offline

#4 2017-01-25 16:11:37

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,655
Website

Re: Exception in SynMustache using nested expression helpers

Because VariantToRawByteString are not true text variants which are compatible with JSON and mustache, but some custom variant types to be used internally for data transfert.

Offline

#5 2017-01-25 16:47:43

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 337

Re: Exception in SynMustache using nested expression helpers

Ok, but in the sample application I am not using VariantToRawByteString, but direct use of Base64ToBin and BinToBase64.


Esteban

Offline

#6 2017-01-25 20:16:13

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 337

Re: Exception in SynMustache using nested expression helpers

I found a solution, is not the better but works for me, I made a copy of "const Value: variant" param and I work with that copy.

class procedure TMainForm.FromBase64(const Value: variant; out result: variant);
var
  lValue: RawByteString;
begin
  lValue := Copy(Value, 1, Length(Value));
  result := SynCommons.Base64ToBin(lValue);
end;

class procedure TMainForm.ToBase64(const Value: variant; out result: variant);
var
  lValue: RawByteString;
begin
  lValue := Copy(Value, 1, Length(Value));
  result := SynCommons.BinToBase64(lValue);
end;

@ab, is there a better solution ?

Thanks.

Esteban


Esteban

Offline

#7 2017-01-27 11:31:50

EMartin
Member
From: Buenos Aires - Argentina
Registered: 2013-01-09
Posts: 337

Re: Exception in SynMustache using nested expression helpers

Just for curiosity, is not this a bug ? I mean, the sample application fail but with this patch no.

Esteban.


Esteban

Offline

Board footer

Powered by FluxBB