Skip to content

Instantly share code, notes, and snippets.

@pmcgee69
Created May 14, 2024 08:00
Show Gist options
  • Save pmcgee69/f777a02a6212c26597b4c5c86bbb1e9e to your computer and use it in GitHub Desktop.
Save pmcgee69/f777a02a6212c26597b4c5c86bbb1e9e to your computer and use it in GitHub Desktop.
Testing some pointer basics
{$APPTYPE CONSOLE}
program Nulls_in_Delphi;
uses
System.SysUtils;
const nl = sLineBreak;
procedure print(a:pointer;b:longint; s:string);
begin
writeln( longint(a).ToHexString, ' ', b.ToHexString, ' ', s);
end;
type
Tmyrecord = record
s:string
end;
Tmyclass = class
s:string
end;
var i:integer;
s:string;
c:Tmyclass;
r:Tmyrecord;
begin
writeln;
// var i:integer;
// var s:string;
// var c:Tmyclass;
// var r:Tmyrecord;
print( @i, longint(i), 'int');
print( @s, longint(s), 'str');
print( @r, longint(r), 'rec');
print( @c, longint(c), 'class');
writeln(nl,'string');
s := 'abc';
print( @s, longint(s), s);
s := '';
print( @s, longint(s), '"');
writeln(nl,'record');
print( @r, longint(r), '');
r.s := 'abc';
print( @r, longint(r), r.s);
r.s := 'abcd';
print( @r, longint(r), r.s);
writeln(nl,'class');
c := Tmyclass.Create;
print( @c.s, longint(c.s), '');
c.s := 'abc';
print( @c.s, longint(c.s), c.s);
c.s := 'abcd';
print( @c.s, longint(c.s), c.s);
// if c?.s?.length > 0 then ...
// c := nil; // to test short-circuiting
// c.s := '' ;
// c.s := ' ';
if assigned(c) then
if (c.s<>'') then
if (length(c.s)>0) then writeln(nl,length(c.s));
if assigned(c) and (c.s<>'') and (length(c.s)>0) then writeln(nl,length(c.s));
readln;
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment