TROComplexType Boolean Property - not evaluation fail

Just seen a post on StackOverflow that is poorly described but got me thinking (the poster refers to RO SDK)


so assume:

TFoo = class (TROComplexType)
...
published    
  property CanEdit: Boolean read fCanEdit write fCanEdit;
end;

TROStreamSerializer treats boolean true as a value of 255

and looking into TROStreamSerializer.ReadEnumerated I see that the value of fCanEdit would be set to 255 if fCanEdit should be true.

Good so far, except:

var
 temp : Boolean;
begin
  // De-serialize Foo from a stream and CanEdit is set to True
 Assert (Foo.CanEdit); 
 temp := not Foo.CanEdit;
  // temp is true

Inspect the memory and you will see:
Byte (Foo.CanEdit) = 255
Byte (Temp) = 254

Ouch, boolean evaluation on boolean property of TROComplexType does not work as one would expect.

The poster appears to have solved his/her problem, but thought it would be prudent to show what I found contemplating said posters problem.

As a side note I have a fairly oldish version of RO SDK, so maybe it’s already fixed, don’t know.

I can’t reproduce this case with XE5 and BinMessage.
Server-side:

function TNewService.NewMethod: NewStruct;
begin
  Result := NewStruct.Create;
  Result.NewField := true;
end;

client-side:

procedure TClientForm.Button1Click(Sender: TObject);
var
  a: Newstruct;
  b:boolean;
begin
  a := (RORemoteService as INewService).NewMethod;
  b:= not a.NewField ;
  if a.NewField = b then
    raise Exception.Create('a.NewField is equal b')
  else
    ShowMessage('a = '+BoolToStr(a.NewField,True) +', b = '+BoolToStr(b,True));
end;