Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VCL Issue - TImage* Naming using variables?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm trying to make a program move an image to new coordinates, but using the caption of a static text box as the name of the image (because it needs to be changed, and writing out if statements for 100 images would be completly too time consuming)...

((TImage*)Let1->Caption)->

This is the code idea, I have the static text box "Let1" given a caption by another form. I want the resulting caption to be used as the name of the image (the images on this particular form have the correct names). When trying this, I get the error Cannot cast from AnsiString to TImage *. How can I get around this, without massive amounts of typing???
 
This is NOT the way to do it. You're trying to convert the Label's caption, which is an AnsiString, into a TShape. ( I can see how you thought this would work [smile]). You can use (TShape *)Form1->Components[n] to get the nth component on the form, but I'm unsure how to do it by name, other than looping through each component and seeing if its name matches the label's caption.
Code:
for (int i = 0; i < Form1->ComponentCount; i++) {
     if (Form1->Components[n]->Name == Let1->Caption) {
          TShape *shp = dynamic_cast<TShape *>(Form1->Components[i]);
          shp->Brush->Color = clRed;
          // Other stuff with shp
          }
     }

There's probably a more efficient way of doing this using component name {eg. Form1->ComponentWithName(&quot;Shape1&quot;)}. Maybe someone else can help with this part! [pc3]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top