program CheckBlankOrEmpty;
function IsBlankOrEmpty(str: PChar): Boolean;
var
i: Integer;
begin
// Check for NULL pointer
if str = nil then
Exit(True);
// Iterate through the string to check for non-whitespace characters
i := 0;
while str[i] <> #0 do
begin
if not (str[i] in [' ', #9, #10, #13]) then // Space, Tab, Line Feed, Carriage Return
Exit(False);
Inc(i);
end;
Exit(True);
end;
var
test1, test2, test3, test4: PChar;
begin
test1 := nil; // NULL string pointer
test2 := ''; // Empty string
test3 := ' '; // Whitespace only
test4 := 'abc'; // Non-empty string
WriteLn('Test1: ', IsBlankOrEmpty(test1));
WriteLn('Test2: ', IsBlankOrEmpty(test2));
WriteLn('Test3: ', IsBlankOrEmpty(test3));
WriteLn('Test4: ', IsBlankOrEmpty(test4));
end.
(*
run:
Test1: TRUE
Test2: TRUE
Test3: TRUE
Test4: FALSE
*)