CompareMem doesn't seem to work when using a value that comes from an array

So I have a test case in my program

procedure MemCheck<T>(x, y : T);
var
    a, b : T;
    vals : array of T;
    c : T;
begin
    a := x;
    b := y;
    c := a;

    SetLength(vals, 4);
    vals[0] := a;
    vals[1] := a;
    vals[2] := a;
    vals[3] := a;

    c := T(vals[2]); //c := a ; workes fine 

    Check
    (
        CompareMem(@c, @y, SizeOf(T)),
        'Memory compare check'
    );


end;

This test case fails and I'm not sure why

MemCheck<String>('a', 'a');

it works fine when i use

c := a ; instead c := T(vals[2]);

+4
source share
1 answer

MemCheck(). , . , x y. -1. String - .

, vals, a, b c . . System.StringRefCount() , -1, , .

vals[2] := a;, a , RTL String . a -1, vals[2] 1, , . c := T(vals[2]); String String, . StringRefCount() , c 2.

CompareMem(), , , String, , .

c := T(vals[2]); c := a;, a , - c - . , CompareMem() , String, , .

, : vals[2] := a; , - String := String;?

a := x;, b := y; c := a; System.@UStrLAsg(), String , - String, .

vals[2] := a; System.@UStrAsg(), , String .

@UStrAsg() @UStrLAsg() vals[2] := a;? , , String , . vals (vals: array[0..3] of String;), @UStrLAsg() @UStrAsg(), CompareMem().

@UStrLAsg() String String, -.

@UStrAsg() String String, , , DLL/, .

, , , String .

+16

All Articles