Solved

LoadFromFile in C++ Builder

Posted on 1997-10-27
4
3,228 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
  • 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

770 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