Board index » cppbuilder » Load files...

Load files...


2003-10-16 06:26:32 PM
cppbuilder101
Hi,
My program has to load pictures from harddisk or cd rom, depends if the user
has it installed or not.
The question: How can I put to AnsiStrings together??? The first saves to
drive, the second the path.
My Code:
apppath = ExtractFileDrive(GetCurrentDir());
AnsiString bpath = apppath+("\\BCB projs\\CD4\\003_1.jpg");
Edit1->Text = apppath + bpath;
But Edit1 show me only the content of bpath....
Thanks for your help
Christoph
 
 

Re:Load files...

"Christoph" < XXXX@XXXXX.COM >wrote:
Quote
[...] How can I put to AnsiStrings together???
The AnsiString Constructor doesn't like mixed types. You can
fix that by casting:
AnsiString bpath = (AnsiString) ExtractFileDrive( GetCurrentDir() ) + (AnsiString) "/BCB projs/CD4/003_1.jpg";
I think the first cast isn't needed.
~ JD
 

Re:Load files...

Thats work! Thanks
Christoph
 

{smallsort}

Re:Load files...

JD wrote:
Quote
AnsiString bpath = (AnsiString) ExtractFileDrive( GetCurrentDir() ) + (AnsiString) "/BCB projs/CD4/003_1.jpg";

I think the first cast isn't needed.
Nor the second.
Hans.
 

Re:Load files...

"Christoph" < XXXX@XXXXX.COM >wrote in message
Quote
apppath = ExtractFileDrive(GetCurrentDir());
Try using Application->ExeName rather than GetCurrentDir().
apppath = ExtractFileDrive(Application->ExeName);
Quote
But Edit1 show me only the content of bpath....
That would be true if apppath was empty, which would happen if
GetCurrentDir() returned an empty string in the first place.
Gambit
 

Re:Load files...

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
The AnsiString Constructor doesn't like mixed types.
There is nothing wrong with the Christoph's original code. This is not a
matter of AnsiString constructors. The apppath variable is already an
AnsiString. Adding the rest of the path to the apppath variable is invoking
the '+' concatentation operator, which takes an AnsiString. AnsiString has
a constructor which takes a char*, so this line:
AnsiString bpath = apppath+("\\BCB projs\\CD4\\003_1.jpg");
Is effectively the exactl same as this:
AnsiString bpath = apppath + AnsiString("\\BCB projs\\CD4\\003_1.jpg");
Gambit
 

Re:Load files...

Apppath has the "value" C: , I tryed it. Thanks alot for your help. I just
finished the program: A Viewer for holiday photos, including a nice
slideshow. :)
Christoph
 

Re:Load files...

"Remy Lebeau \(TeamB\)" < XXXX@XXXXX.COM >wrote:
Quote
This is not a matter of AnsiString constructors.
Yup. My memory must be failing.
String s = "C:/";
s += Buffer + "/Test.dat";
where Buffer is a char* gives an invalid pointer addition
error - as it should. But if one casts ...
s += (String)Buffer + (String)"/Test.dat";
compiles and executes correctly.
~ JD
 

Re:Load files...

"JD" < XXXX@XXXXX.COM >wrote in message
Quote
String s = "C:/";
s += Buffer + "/Test.dat";

where Buffer is a char* gives an invalid pointer addition error - as it
should.
Correct. That code is interpreted by the compiler as the following:
String s = "C:/";
s += (Buffer + "/Test.dat");
A char* cannot be concetenated to another char* via the '+' operator, it
will perform pointer arithmetic instead, which is not the same thing.
But if one casts ...
Quote
s += (String)Buffer + (String)"/Test.dat";

compiles and executes correctly.
That is because the compiler interprets it as the following:
s += (AnsiString(Buffer) + AnsiString("/Test.dat"));
AnsiString does have a '+' operator for concatenation, and then the
resulting AnsiString is passed to '+=' which also accepts an AnsiString.
Gambit