Post by Leo SiefertPost by unknownOf course the real problem is that the bug also
occurs in VCL classes with AsString properties.
Can you show an example of where this is a problem? I did try your
code and it runs without a problem for me and I can find no evidence
that anything is being improperly deleted. I added a destructor to
TMyClass that announces destruction and all I see is a single
destruction of TMyClass{"No"), as I would expect.
I just tried it with 2006 and got the access violation, read of address 2.
First-if-test-fail jumps to 004022DF where you can pick up the trail.
Offending code starts at 0040231D.
if(SameText(TMyClass("No").AsString, "Yes") &&
SameText(TMyClass("Yes").AsString, "No"))
t1 = AnsiString("Yes") bp-10h
t2 = AnsiString("No") bp-4
t3 = TMyClass(bp-8,t2) bp-50h
t4 = AnsiString() bp-54h
AnsiString::operator = ( t4, t3 )
SameText( t4, t1 )
test fails
[skipped code]
flag = 0 !!
~AnsiString t1
~AnsiString bp-8 ? tMyClass.FStr ?
~AnsiString t2
test flag !!
missing jump on flag !!
~AnsiString bp-1ch Not Set! Set by second test
~AnsiString bp-0ch
Function Adresses:
00402DD8 __InitExceptBlockLDTC(void *):
00402350 TMyClass(const AnsiString &s) : FStr(s) { };
00401D6C System::AnsiString::AnsiString():
004036a6 rtl100.__fastcall Sysutils::SameText(const System::AnsiString,
const System::AnsiString):
LongPath1.cpp.150: void __fastcall TForm1::Button2Click(TObject *Sender)
004021C0 55 push ebp
004021C1 8BEC mov ebp,esp
004021C3 83C4A4 add esp,-$5c
004021C6 8955B4 mov [ebp-$4c],edx
004021C9 8945B8 mov [ebp-$48],eax
004021CC B8D4454000 mov eax,$004045d4
004021D1 E8020C0000 call $00402dd8
LongPath1.cpp.152: if(SameText(TMyClass("No").AsString, "Yes") &&
004021D6 BA85434000 mov edx,$00404385 "Yes"
004021DB 8D45F0 lea eax,[ebp-$10]
004021DE E89D0E0000 call System::AnsiString::AnsiString(const char *)
004021E3 FF45D8 inc dword ptr [ebp-$28]
004021E6 FF30 push dword ptr [eax] save for SameText()
004021E8 66C745CC0C00 mov word ptr [ebp-$34],$000c
004021EE BA82434000 mov edx,$00404382 "No"
004021F3 8D45FC lea eax,[ebp-$04]
004021F6 E8850E0000 call System::AnsiString::AnsiString(const char *)
004021FB FF45D8 inc dword ptr [ebp-$28]
004021FE 8D55FC lea edx,[ebp-$04]
00402201 52 push edx
00402202 8D4DF8 lea ecx,[ebp-$08]
00402205 51 push ecx
00402206 E845010000 call $00402350 TMyClass::TMyClass
0040220B 83C408 add esp,$08
0040220E 8345D802 add dword ptr [ebp-$28],$02
00402212 8945B0 mov [ebp-$50],eax
00402215 8D45F4 lea eax,[ebp-$0c]
00402218 E84FFBFFFF call $00401d6c AnsiString::AnsiString(AnsiString)
0040221D FF45D8 inc dword ptr [ebp-$28]
00402220 8945AC mov [ebp-$54],eax
00402223 8B55B0 mov edx,[ebp-$50]
00402226 8B45AC mov eax,[ebp-$54]
00402229 E83A0F0000 call System::AnsiString::operator =(const System::AnsiString &)
0040222E 8D45F4 lea eax,[ebp-$0c]
00402231 8B00 mov eax,[eax]
00402233 5A pop edx
00402234 E86D140000 call $004036a6 SameText
00402239 84C0 test al,al
0040223B 0F849E000000 jz $004022df Fail first test
00402241 BA82434000 mov edx,$00404382
00402246 8D45E0 lea eax,[ebp-$20]
00402249 E8320E0000 call System::AnsiString::AnsiString(const char *)
0040224E FF45D8 inc dword ptr [ebp-$28]
00402251 FF30 push dword ptr [eax]
00402253 BA85434000 mov edx,$00404385
00402258 8D45EC lea eax,[ebp-$14]
0040225B E8200E0000 call System::AnsiString::AnsiString(const char *)
00402260 FF45D8 inc dword ptr [ebp-$28]
00402263 8D4DEC lea ecx,[ebp-$14]
00402266 51 push ecx
00402267 8D45E8 lea eax,[ebp-$18]
0040226A 50 push eax
0040226B E8E0000000 call $00402350
00402270 83C408 add esp,$08
00402273 8345D802 add dword ptr [ebp-$28],$02
00402277 8945A8 mov [ebp-$58],eax
0040227A 8D45E4 lea eax,[ebp-$1c]
0040227D E8EAFAFFFF call $00401d6c
00402282 FF45D8 inc dword ptr [ebp-$28]
00402285 8945A4 mov [ebp-$5c],eax
00402288 8B55A8 mov edx,[ebp-$58]
0040228B 8B45A4 mov eax,[ebp-$5c]
0040228E E8D50E0000 call System::AnsiString::operator =(const System::AnsiString &)
00402293 8D45E4 lea eax,[ebp-$1c]
00402296 8B00 mov eax,[eax]
00402298 5A pop edx
00402299 E808140000 call $004036a6
0040229E 84C0 test al,al
004022A0 0F95C1 setnz cl
004022A3 83E101 and ecx,$01
004022A6 51 push ecx
004022A7 FF4DD8 dec dword ptr [ebp-$28]
004022AA 8D45E0 lea eax,[ebp-$20]
004022AD BA02000000 mov edx,$00000002
004022B2 E8810E0000 call System::AnsiString::~AnsiString()
004022B7 FF4DD8 dec dword ptr [ebp-$28]
004022BA FF4DD8 dec dword ptr [ebp-$28]
004022BD 8D45E8 lea eax,[ebp-$18]
004022C0 BA02000000 mov edx,$00000002
004022C5 E86E0E0000 call System::AnsiString::~AnsiString()
004022CA FF4DD8 dec dword ptr [ebp-$28]
004022CD 8D45EC lea eax,[ebp-$14]
004022D0 BA02000000 mov edx,$00000002
004022D5 E85E0E0000 call System::AnsiString::~AnsiString()
004022DA 59 pop ecx
004022DB 85C9 test ecx,ecx
004022DD 7504 jnz $004022e3
004022DF 33C0 xor eax,eax
004022E1 EB05 jmp $004022e8
004022E3 B801000000 mov eax,$00000001
004022E8 50 push eax
004022E9 FF4DD8 dec dword ptr [ebp-$28]
004022EC 8D45F0 lea eax,[ebp-$10]
004022EF BA02000000 mov edx,$00000002
004022F4 E83F0E0000 call System::AnsiString::~AnsiString()
004022F9 FF4DD8 dec dword ptr [ebp-$28]
004022FC FF4DD8 dec dword ptr [ebp-$28]
004022FF 8D45F8 lea eax,[ebp-$08]
00402302 BA02000000 mov edx,$00000002
00402307 E82C0E0000 call System::AnsiString::~AnsiString()
0040230C FF4DD8 dec dword ptr [ebp-$28]
0040230F 8D45FC lea eax,[ebp-$04]
00402312 BA02000000 mov edx,$00000002
00402317 E81C0E0000 call System::AnsiString::~AnsiString()
0040231C 59 pop ecx
0040231D 84C9 test cl,cl
Bad Test. Does nothing with result!
LongPath1.cpp.158: }
0040231F FF4DD8 dec dword ptr [ebp-$28]
00402322 8D45E4 lea eax,[ebp-$1c]
00402325 BA02000000 mov edx,$00000002
0040232A E8090E0000 call System::AnsiString::~AnsiString()
0040232F FF4DD8 dec dword ptr [ebp-$28]
00402332 8D45F4 lea eax,[ebp-$0c]
00402335 BA02000000 mov edx,$00000002
0040233A E8F90D0000 call System::AnsiString::~AnsiString()
0040233F 8B4DBC mov ecx,[ebp-$44]
00402342 64890D00000000 mov fs:[$00000000],ecx
LongPath1.cpp.158: }
00402349 8BE5 mov esp,ebp
0040234B 5D pop ebp
0040234C C3 ret