问题
I have
property Background: TPicture read FBackground write SetBackground;
if nothing is ever assiged to it, what would the value be of background?
i have tried
if Background = NULL then
begin
...
..
...
end;
回答1:
It depends. When the field is created in the constructor and FBackground is assigned, then use:
if FBackground.Graphic = nil then
Or:
if not Assigned(FBackground.Graphic) then
If the Graphic is assigned, then use:
if FBackground.Graphic.Empty then
And if both property and field are unassigned then use:
if FBackground = nil then
Or:
if not Assigned(FBackground) then
All of the above combined:
if (FBackground = nil) or (FBackground.Graphic = nil) or FBackground.Graphic.Empty then
来源:https://stackoverflow.com/questions/19439202/background-value-if-empty