whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

27 Visitors Online


 
...Get the reference count of an AnsiString?
Autor: P. Below
[ Print tip ]  

Tip Rating (4):  
     



function GetAnsistringRefcount(const S: string): Cardinal;
asm
  
or eax, eax
  jz @done
  sub eax, 8
  mov eax, dword ptr [eax]
@done:
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  
S1, S2: string;
begin
  
memo1.lines.Add(Format('Refcount at start: %d',
    [GetAnsistringRefcount(S1)]));
  S1 := StringOfChar('A', 10);
  memo1.lines.Add(Format('Refcount after assignment: %d',
    [GetAnsistringRefcount(S1)]));
  S2 := S1;
  memo1.lines.Add(Format('Refcount after S2:=S1: %d',
    [GetAnsistringRefcount(S1)]));
  S2 := S1 + S2;
  memo1.lines.Add(Format('Refcount after S2:=S1+S2: %d',
    [GetAnsistringRefcount(S1)]));
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners