I am stomped by a strange behaviour of sprintf when applied to the "Caption" property of a form.
The following code works as expected:
Form1->Caption = temp;
However, this simplified version doesn't (the value of "Caption" doesn't change):
BTW the following also works:
Form1->Caption = Form1->Caption.sprintf (L"123");
Since Caption is a Unicode string, I don't understand why the 2nd version wouldn't work. What am I missing here?
The statement Form1->Caption = temp; assigns the value of temp to the PROPERTY called Caption in the class Form1. Under the cover this assignment can (and usually does) hide a lot of other necessary activity (typically by actually calling a WriteTheProperty() [my name] method). In your particular case updating the property will also ensure that the painting of the form on the screen also updates the caption. Your example that doesn't work: Form1->Caption.sprintf (L"123"); will make the actual string Form1->Caption equal to "123" but, because it doesn't use the "=" notation it doesn't call the property WriteTheProperty() method so the form displayed caption fails to update. For more information (and perhaps a better explanation!) search for