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!

Converting AnsiString to char

Status
Not open for further replies.

max23

Programmer
Oct 5, 2007
2
ES
The following working code is used to delete the contents of the c:\temp directory.

char *File = "C:\\temp\\*.???\0";

SHFILEOPSTRUCT op;
ZeroMemory(&op, sizeof(op));
op.hwnd = Handle;
op.wFunc = FO_DELETE;
op.pFrom = File;
op.fFlags=FOF_NOCONFIRMATION;
SHFileOperation( &op);

I want to be able to subsitute the "C:\\temp\\*.???\0" with a string as read from a Label1->Caption but I get a compiler error, can't convert AnsiString to char.

Is there a simple way to make the following work?

Label1->Caption="C:\\temp\\*.???\0";

char *File = Label1->Caption; //this line doesn't work!!!

etc
etc
etc
 
Try to replace that Line by

char File[xx]; // xx=Size of the Array

strcpy(File,Label->Caption.c_str());


The function c_str converts from Borland String to a regular String.

The other way would be

String File;
File=Label1->Caption;

hnd
hasso55@yahoo.com

 
Max23,

if you use char-pointers (like FILE) do never forget to assign place for the data (in this case the filepath) you want to store. char* just assigns 1 place for the pointer, if you do f.i.: char FILE[25] you make an array for 24 characters (+ the zero end) and FILE is the pointer to the first character of that row, FILE[0] is the first character of the row. Be sure you understand this, otherwise you are going to get strange effects when you store data in FILE and new variables will overwrite this data. This is very essential when programming in C++ and using pointers.

Wim Vanherp
Wim.Vanherp@myself.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top