I am trying to make a TImage move like a DVD logo, but the TImage is not moving.
This is the code I used:
void __fastcall TForm1::DVDLogoTimer(TObject *Sender)
{
image->Left+=xPos; image->Top+=yPos;
if (image->Left <= invisibleHelperObject->Left) xPos=-xPos;
if (image->Top <= invisibleHelperObject->Top) yPos=-yPos;
if (image->Left+image->Width >= invisibleHelperObject->Width) xPos=-xPos;
if (image->Top+image->Height >= invisibleHelperObject->Height) yPos=-yPos;
Label1->Caption = IntToStr(xPos) + " | " + IntToStr(yPos);
}
(X and Y variables are not even changing (stays at 0))
In C++Builder 6 (and the "classic" Borland compiler in modern versions), you can't use compound operators like
+=with properties. Doing so will read the property value into a temporary and then modify the temporary, but will not assign the temporary back to the property. Using compound operators on properties requires a modern Clang-based compiler:Differences Between Clang-enhanced C++ Compilers and Previous Generation C++ Compilers, __property: Compound and Chained Assignment
So, in your situation, when you invoke
image->Left += xPos;for instance, it acts as-if you had written this instead:So, you need to use the
+and=operators separately instead, eg: