Answer the question
In order to leave comments, you need to log in
How to assign a boolean expression to a TObject field?
There is a class with a field type TObject.
The field value can be a boolean type or another class.
It is not possible to assign a boolean value to it, type conversions (explicit or as TObject) do not help.
Is it possible to do this at all, maybe it's worth somehow making your own TBoolean ?!
TBar = class
field : TObject;
end;
...
var
bar : TBar;
...
bar.field := True;
Answer the question
In order to leave comments, you need to log in
I'll try to guess the problem. There is a certain field (let's call it UserData), but we have boolean user data!
Solution 1: Direct conversion regardless of type incompatibilities.
someObj.UserData := TObject(true);
someBool := boolean(someObj.UserData);
someObj.UserData := dummyObject;
someBool := (someObj.UserData <> nil);
initialization
dummyObject := TObject.Create;
finalization
dummyObject.Free;
end.
TBoolObject = class
public
Value : boolean;
// конструкторы опущу, деструктор не нужен
end.
someObj.UserData := TBoolObject(true);
someBool := (someObj.UserData as TBoolObject).Value;
TObjBool = record
case integer of
0 : ( asObj : TObject );
1 : ( asBool : boolean );
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question