C++ Builder 6 - Opening a File

How to open a file (for reading) in C++ Builder using codes?

Comments

  • : How to open a file (for reading) in C++ Builder using codes?
    If it is a text file, you could use a TRichEdit to load it:
    [code]
    RichEdit1->Lines->LoadFromFile("myFile.txt");
    [/code]

    Good luck,



    bilderbikkel

  • : : How to open a file (for reading) in C++ Builder using codes?
    : If it is a text file, you could use a TRichEdit to load it:
    : [code]
    : RichEdit1->Lines->LoadFromFile("myFile.txt");
    : [/code]
    :
    : Good luck,
    :
    :
    :
    : bilderbikkel
    :
    :
    I should be able to open any type of file (eg .doc,.pdf,.xls).
    I don't want to open it in a richtext.
    is there a way to open it directly?

    Kind Regards,
    Rowin

  • Sure:

    [code]
    #include
    const int fileHandle = OpenFile("MyFile.pdf);
    [/code]

    You can check out the help of the functions in SysUtils yourself: go into this file (press CTRL-ENTER on the #include statement) and scroll down entirely.

    You could also remain STL and use std::ifstream if you'd like. See http://codepedia.com/1/cppFileIO

    Have fun,
    bilderbikkel

  • : Sure:
    :
    : [code]
    : #include
    : const int fileHandle = OpenFile("MyFile.pdf);
    : [/code]
    :
    : You can check out the help of the functions in SysUtils yourself: go into this file (press CTRL-ENTER on the #include statement) and scroll down entirely.
    :
    : You could also remain STL and use std::ifstream if you'd like. See http://codepedia.com/1/cppFileIO
    :
    : Have fun,
    : bilderbikkel
    :
    :

    Thanks for the above code,
    but when I tried it, I got the following error:
    [C++ Error] Unit1.cpp(110): E2193 Too few parameters in call to '__stdcall OpenFile(const char *,_OFSTRUCT *,unsigned int)'


    Do you have any idea why?

    Kind Regards,
    Rowin

  • : but when I tried it, I got the following error:
    : [C++ Error] Unit1.cpp(110): E2193 Too few parameters in call to '__stdcall OpenFile(const char *,_OFSTRUCT *,unsigned int)'
    :
    :
    : Do you have any idea why?
    Yes, I pressed F1 when my cursus was on OpenFile. The help stated me also to give an access mode (by an int). So, give it that additional int.

    Good luck,
    bilderbikkel

  • Hi,
    What value should I give to _OFSTRUCT*?

    Will I be able to do the following with the above code?
    I choose a file from a FileListBox, click on a button and the file opens? (Exactly like if you choose a file from your desktop, double click on it and it opens)

    Kind Regards,
    Rowin
  • : What value should I give to _OFSTRUCT*?

    YOU have to create an _OFSTRUCT. When the file is opened, you can access this file by this struct.

    Good luck,
    bilderbikkel

  • I've used the following and it works:
    ShellExecute()


    Kind Regards,
    Rowin
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories