Board index » cppbuilder » Simple error but can't fix it

Simple error but can't fix it


2006-07-07 10:03:03 PM
cppbuilder92
I am new to C++ Builder and using version 5 in XP. I am getting error
message in following line:
CustPicID->Picture->LoadFromFile(" `ID_PATH` + none.bmp");
I've used same code line in prior C++ Builder version and it has worked.
I'hve defined ID_PATH as \\MyDir\\ earlier in the code and I've verified
none.bmp exist in that directory.
I have not programmed for sometime. So, this should be simple but I can't
fix it. Please help.
Sanjay Patel
 
 

Re:Simple error but can't fix it

If
String ID_PATH = "\\MyDir\\" ;
just use:
CustPicID->Picture->LoadFromFile(ID_PATH + "none.bmp") ;
That should work.
Best regards
Pedro
"Sanjay Patel" < XXXX@XXXXX.COM >escribi?en el mensaje
Quote
I am new to C++ Builder and using version 5 in XP. I am getting error
message in following line:

CustPicID->Picture->LoadFromFile(" `ID_PATH` + none.bmp");

I've used same code line in prior C++ Builder version and it has worked.
I'hve defined ID_PATH as \\MyDir\\ earlier in the code and I've verified
none.bmp exist in that directory.

I have not programmed for sometime. So, this should be simple but I can't
fix it. Please help.

Sanjay Patel

 

Re:Simple error but can't fix it

"Pedro Fehlauer" < XXXX@XXXXX.COM >wrote in message
Quote
If

String ID_PATH = "\\MyDir\\" ;

just use:

CustPicID->Picture->LoadFromFile(ID_PATH + "none.bmp") ;
On the other hand, if ID_PATH is a #define instead, ie:
#define ID_PATH "\\MyDir\\"
Then you will have to cast one or both of the char* literals to an
AnsiString, as you can't add two char* literals together directly. For
example:
CustPicID->Picture->LoadFromFile(AnsiString(ID_PATH) + "none.bmp");
Or:
CustPicID->Picture->LoadFromFile(ID_PATH + AnsiString("none.bmp"));
Or:
CustPicID->Picture->LoadFromFile(AnsiString(ID_PATH) +
AnsiString("none.bmp"));
Gambit
 

{smallsort}

Re:Simple error but can't fix it

Pedro and Remy,
Thank you very much! Following worked:
CustPicID->Picture->LoadFromFile(AnsiString(ID_PATH) + "none.bmp");
Thanks Again!
Sanjay T. Patel
"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
Quote

"Pedro Fehlauer" < XXXX@XXXXX.COM >wrote in message
news:44ae7250$ XXXX@XXXXX.COM ...

>If
>
>String ID_PATH = "\\MyDir\\" ;
>
>just use:
>
>CustPicID->Picture->LoadFromFile(ID_PATH + "none.bmp") ;

On the other hand, if ID_PATH is a #define instead, ie:

#define ID_PATH "\\MyDir\\"

Then you will have to cast one or both of the char* literals to an
AnsiString, as you can't add two char* literals together directly. For
example:

CustPicID->Picture->LoadFromFile(AnsiString(ID_PATH) + "none.bmp");

Or:

CustPicID->Picture->LoadFromFile(ID_PATH + AnsiString("none.bmp"));

Or:

CustPicID->Picture->LoadFromFile(AnsiString(ID_PATH) +
AnsiString("none.bmp"));


Gambit


 

Re:Simple error but can't fix it

Sanjay Patel skrev:
Quote
I am new to C++ Builder and using version 5 in XP. I am getting error
message in following line:

CustPicID->Picture->LoadFromFile(" `ID_PATH` + none.bmp");

I've used same code line in prior C++ Builder version and it has worked.
I'hve defined ID_PATH as \\MyDir\\ earlier in the code and I've verified
none.bmp exist in that directory.

I have not programmed for sometime. So, this should be simple but I can't
fix it. Please help.

Sanjay Patel


Check out the placement of
citation marks in
CustPicID->Picture->LoadFromFile("
`ID_PATH` + none.bmp");
Should look like:
CustPicID->Picture->LoadFromFile(
ID_PATH + "none.bmp");
Björn
 

Re:Simple error but can't fix it

Just a general tip, try to avoid the use of "#define", use "const" instead.
Const works exactly the same as #define (it does not use runtime memory),
but adds a major advantage: it's error safe, since it checks types at
compilation time.
rgds.
Pedro
"Sanjay Patel" < XXXX@XXXXX.COM >escribi?en el mensaje
Quote
Pedro and Remy,

Thank you very much! Following worked:

CustPicID->Picture->LoadFromFile(AnsiString(ID_PATH) + "none.bmp");

Thanks Again!
Sanjay T. Patel

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
news:44ae90a6$ XXXX@XXXXX.COM ...
>
>"Pedro Fehlauer" < XXXX@XXXXX.COM >wrote in message
>news:44ae7250$ XXXX@XXXXX.COM ...
>
>>If
>>
>>String ID_PATH = "\\MyDir\\" ;
>>
>>just use:
>>
>>CustPicID->Picture->LoadFromFile(ID_PATH + "none.bmp") ;
>
>On the other hand, if ID_PATH is a #define instead, ie:
>
>#define ID_PATH "\\MyDir\\"
>
>Then you will have to cast one or both of the char* literals to an
>AnsiString, as you can't add two char* literals together directly. For
>example:
>
>CustPicID->Picture->LoadFromFile(AnsiString(ID_PATH) + "none.bmp");
>
>Or:
>
>CustPicID->Picture->LoadFromFile(ID_PATH + AnsiString("none.bmp"));
>
>Or:
>
>CustPicID->Picture->LoadFromFile(AnsiString(ID_PATH) +
>AnsiString("none.bmp"));
>
>
>Gambit
>
>