mirror of
				https://gitlab.com/freepascal.org/fpc/source.git
				synced 2025-11-04 01:01:05 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			40 lines
		
	
	
		
			696 B
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
			
		
		
	
	
			40 lines
		
	
	
		
			696 B
		
	
	
	
		
			ObjectPascal
		
	
	
	
	
	
{$mode objfpc}
 | 
						|
 | 
						|
type
 | 
						|
  pobj = ^tobj;
 | 
						|
  tobj = object
 | 
						|
    a: ansistring;
 | 
						|
    constructor init(s: ansistring);
 | 
						|
    destructor done;
 | 
						|
  end;
 | 
						|
 | 
						|
  PAnsiRec = ^TAnsiRec;
 | 
						|
  TAnsiRec = Packed Record
 | 
						|
    Maxlen,
 | 
						|
    len,
 | 
						|
    ref   : Longint;
 | 
						|
    First : Char;
 | 
						|
  end;
 | 
						|
 | 
						|
const firstoff = sizeof(tansirec)-1;
 | 
						|
 | 
						|
var o: pobj;
 | 
						|
    t: ansistring;
 | 
						|
 | 
						|
constructor tobj.init(s: ansistring);
 | 
						|
begin
 | 
						|
  a := s;
 | 
						|
end;
 | 
						|
 | 
						|
destructor tobj.done;
 | 
						|
begin
 | 
						|
end;
 | 
						|
 | 
						|
begin
 | 
						|
  readln(t);
 | 
						|
  writeln('refcount before init: ',pansirec(pointer(t)-firstoff)^.ref);
 | 
						|
  new(o,init(t));
 | 
						|
  writeln('refcount after init: ',pansirec(pointer(t)-firstoff)^.ref);
 | 
						|
  dispose(o,done);
 | 
						|
  writeln('refcount after done: ',pansirec(pointer(t)-firstoff)^.ref);
 | 
						|
end. |