Guid empty string comparison

Properties
PC0015 Error Design Code Fix Ignore Obsolete

Directly comparing a Guid to an empty string ('') causes a runtime error. When the comparison evaluates, the runtime attempts to parse the empty string into a Guid. An empty string is not a valid Guid format, so parsing fails and an exception is raised.

Use IsNullGuid to check whether a Guid variable holds an empty value.

Example

procedure CheckGuid(Id: Guid)
begin
    if Id = '' then // Guid empty string comparison [PC0015]
        exit;
end;

Replace the comparison with IsNullGuid. For <> comparisons, use not IsNullGuid.

procedure CheckGuid(Id: Guid)
begin
    if IsNullGuid(Id) then
        exit;
end;

See also