Hi all!
My first post here.
I have a question about FileWrite(int Handle, const void *Buffer, unsigned Count) function in C++ Builder 6. How do I write Ansistring into the file using this function?
Here is a code sample. Everything works fine. File 11_10_2004.txt has string "Simple text" in it.
//------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
AnsiString FileName;
const void *FileInput = "Simple text";
int FileHandle;
FileName = "Logs\\" + DateToStr(Date()) + ".txt"; //Forming file name
FileName[8]='_';
FileName[11]='_';
if (FileExists(FileName)) //obtain file handle
{ FileHandle = FileOpen(FileName, fmOpenWrite);}
else
{ FileHandle = FileCreate(FileName);}
FileWrite(FileHandle, FileInput, strlen("Simple text")); //write smth into file
FileClose(FileHandle);
}
//----------------------------
However I want a text from Label component to be copied into the file. I change code a little to look like this:
//------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
AnsiString FileName;
const void *FileInput = Label1->Caption;;
int FileHandle;
FileName = "Logs\\" + DateToStr(Date()) + ".txt"; //Forming file name
FileName[8]='_';
FileName[11]='_';
if (FileExists(FileName)) //obtain file handle
{FileHandle = FileOpen(FileName, fmOpenWrite);}
else
{ FileHandle = FileCreate(FileName);}
FileWrite(FileHandle, FileInput, sizeof(Label1->Caption)); //write smth into file
FileClose(FileHandle);
}
//----------------------------
And get Error E2034 cannot convert 'Ansistring' to 'const void*'.
I know it's a type mismatch, but how do i resolve it? How do I copy text from Label1->Caption (AnsiString) into the file?
Thanks.