Solved

LoadFromFile in C++ Builder

Posted on 1997-10-27
4
3,356 Views
Last Modified: 2011-10-03
In my program i try to load several Bitmaps while the program is running. In Delphi 2.0 exists the method
LoadFromFile. Using this method the following code works
Image1.Picture.LoadFromFile('C:\pictures\example.bmp');.
The analogous code using the -> operator instead of the . operator doesn't work. Who can me post an exmple using this
method in Borland C++ builder environment. Thank you
yours Thorsten
0
Comment
Question by:thorsten
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
cph earned 100 total points
ID: 1172116
To load a bitmap into an image control's picture pass the name of a bitmap file to the picture's LoadFromFile method:

void __fastcall TForm1::FormCreate(TObject *Sender)
{
   Image1->Picture->LoadFromFile("c:\\windows\\athena.bmp");
}

The picture recognizes .BMP as the standard extension for bitmap files, so it creates its graphic as a TBitmap, then calls that graphic's LoadFromFile method. Because the graphic is a bitmap, it loads the image from the file as a bitmap.

Hope this help,

CpH
0
 
LVL 1

Expert Comment

by:cph
ID: 1172117
Oupps... here is the complete source file :-)

//---------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
      : TForm(Owner)
{
}
//---------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
   Image1->Picture->LoadFromFile("c:\\windows\\athena.bmp");
}
//---------------------------------------------------------------

Sorry about this,
CpH
0
 

Author Comment

by:thorsten
ID: 1172118
Hallo cph!
Thank you for your answer. But I wonder why I have to use the double backslash. Why is this not written  in the help file.
Yours Thorsten.  
0
 
LVL 2

Expert Comment

by:maggc
ID: 22441060
Double backslash must be used because the single backslash is a special escape character. It is not accepted.

The double backslash is in fact only 1 byte of code!

char c;
c = '\\'; // works! a character can take only 1 byte

So:

c:\1.txt  --> c:\\1.txt   (in your code)

\\server\share\1.txt  --> \\\\server\\share\\1.txt
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question