TStringList->LoadFromFile throws exception

c++ builder

    Sponsored Links


  • 1. Default popup menu in standard edit components
    Hi, in C++Builder 2007 I'm missing the default popup menu in standard edit components that was coming up in earlier versions ( BCB5 ) by clicking the right mouse button. Does anybody know how to install this default popup ? Without programming it completely new !! Thanks Philipp Schneider
  • 2. Renaming multiple files
    And I mean multiple, I have like hundreds that I have to rename to insert into a DB. This is my dilemma at the moment. I have filenames in the following format: 20040821.txt (first line: Saturday, August 21, 2004 ) 20050414.txt (first line: Thursday April 14, 2006) 20050415.txt (first line: Friday April 15, 2006) In this format of the file, in the first line of the file the date is already there. But I need to rename the filenames in the following manner. 21 - Saturday.txt 14 - Thursday.txt 15 - Friday.txt My other trillion filenames are in the format of this one. Thursday December 01, 2005.txt Thursday December 08, 2005.txt Thursday December 22, 2005.txt But I still need to rename them to the same format as above. 01 - Thursday.txt 08 - Thursday.txt 22 - Thursday.txt etc. etc.. Does anyone have like a quick one liner of code that will do this? I am really sucky at parsing stuff. Thanks for any help. CJ
  • 3. Managing TDateTimePicker programmatically
    Hello group, I have an application that uses a touch panel for the bulk of its user input. Rather that inflating the size of a TDateTimePicker it contains to accomodate gloved fingers (it looks homely), I'd like to use buttons to navigate/manipulate the DT picker. Is this possible? I haven't been able to deduce the proper keybd_events or WM_ messages to send the little beast - e.g. emitting a VK_DOWN does nothing, whereas a real arrow down decrements the highlighted section of the control - I can't even programmatically highlight a section, for that matter. Any kick in the right direction will be greatly appreciated! Duane
  • 4. Change Cursor
    Hi, I'm trying to change the cursor in my application on an OnMouseDown event. However, the cursor does not actually change until the mouse is up. I've tried in a simple example and no matter what I do, the cursor will only change after the mouse is up. How can I force the cursor to change right after the mousedown event? The following is my sample code. void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { Cursor = crCross; // FormMouseUp(Sender, Button, Shift, X, Y); // Repaint(); // Perform(CM_CURSORCHANGED, 0, 0); // } Thanks -Bill
  • 5. Listview data error
    When I run the application, there is an error in these code: I want to delete an item of Listview, delete (TDataStruct1 *)ListView1->Items->Item[i]->Data; ListView1->Items->Delete(i); Thanks!

TStringList->LoadFromFile throws exception

Postby mataus » Tue, 17 Jun 2008 08:23:31 GMT

Hello all.

I have problem with TStringList->LoadFromFile().  I have to make a program 
that shows information from text log file.  The file is always opened by a 
second program that keeps writtin .

When i call TStringList->LoadFromFile() i get exception "Cannot open file 
C:\Program Files\Company\event log.txt".  I think this is becuase log file 
is openned, by second program.  But notepad can open the file.

Can anyone help me?


Re: TStringList->LoadFromFile throws exception

Postby Remy Lebeau (TeamB) » Wed, 18 Jun 2008 02:08:38 GMT

TStrings::LoadFromFile() attempts to open the file with fmShareDenyWrite 
sharing rights specified.  Since your other app already has the file opened 
for writing, such access will always fail while the other app is using the 
file.  To get around it, you will have to use LoadFromStream() instead. 
That way, you can instantiate your own TFileStream with less restrictive 
sharing rights specified, ie:

    TFileStream *Stream = new TFileStream(FileName, fmOpenRead | 
        delete Stream;


Re: TStringList->LoadFromFile throws exception

Postby Mark Jacobs » Wed, 18 Jun 2008 22:52:34 GMT

That is a lovely example. Thanks Remy.
Mark Jacobs

Similar Threads:

1.throw new Exception() vs. throw Exception()

What is the difference between these two?:

throw new Exception("msg");

throw Exception("msg");

When should I use one vs. the other? 

2.TRegistry->WriteBool() throws exception

Hi all,

I know this might be trivial, but I couldn't locate any post on this with 
search, so I'll have to ask it.

I'm using TRegistry to access the Registry, when I tried to use 
WriteBool(ValName, Value), BCB always give me an exception upon compiling:

Project TCPrinter.exe raised an exception class ERegistryException with 
message 'Failed to set data for 'AutoMode''. Process stopped.

The problem sourced from this block of code:

void __fastcall TForm1::AutoCheckClick(TObject *Sender)
    TRegistry *reg = new TRegistry;
    reg->WriteBool("AutoMode", AutoCheck->Checked);
    delete reg;

AutoCheck is a TCheckBox, AutoMode is the Registry Value Name.

The strange thing is, it's thrown upon compiling, I haven't triggered the 
event yet. I do have a reg->ReadBool() in the constructor, but it never 
caused any problem. I deleted the reg at the end of the constructor, so it's 
not object conflict problem...

Anyone have any idea what's wrong? Thanks in advance. 

3.Can basic_string<>::c_str() throw exceptions?

  Hi all.

  I was wondering. Can the standard basic_string<> c_str()
member function throw any exceptions? Is it perhaps
implementation dependent?

  I tried checking the standard and as far as I can see it is
implementation dependent with no guarantees what so
ever, but I was hoping I may have missed something... :-)

  When the C++ standard does not specify any exception
specifications for some function, nor does it list any
exceptions in the function description. Does that mean
that any exception may be thrown? If that is so, how are
we supposed to prepare for those exceptions in our code
other than 'something happened, I do not know what, but
it was not expected so I'm aborting...'.

  Hope to hear from you soon.

    Jurko Gospodneti?

4.TBitmap.LoadFromFile() throws Stream Error?

Hello all, 

I'm new to Delphi 2005, and have a problem I'm having a difficult time

I have an OwnerDraw TListbox  where basically I'm just drawing
thumbnails of .BMP files in a folder. It works fine, except on SOME
files, the TBitmap.LoadFromFile() throws a stream error.

I can't seem to find out why it does it on these particular .BMP
files. Here's a snippet of the very vanilla code...

 with (Control as TListBox).Canvas do
     If Not FileExists(myListbox.Items[Index]) Then Exit;
        if Bitmap<>nil then
          // Bitmap.PixelFormat := pf24bit; //tryed setting this..it
          // didnt help
          Bitmap.LoadFromFile( myListbox.Items[Index] ); 

The BMP files are small...just approx 98x98
I have found that if I open the troublesome .BMP files and reduce the
color depth to 32K and resave, it makes the stream error disappear. Is
there anything I'm doing obviously wrong in the code? Or is it just
the .BMP files were saved 'strangley'?

5.TSTringList LoadFromFile

"Chad Eddy" < XXXX@XXXXX.COM > wrote in message
news:3f15b185$ XXXX@XXXXX.COM ...
> I am using a TStringList to load files and do some file
> I/O on them.  This works with most files, but not with
> the .doc and .chm's that I try.

Those are not plain-text formats.  Well, .doc may be, but only if it is
encoded in RTF formatting.

> After the load from file, I have a count of 1 line, which
> has a small amount of charachters.

Probably because those formats have binary data in them that is preventing
LoadFromFile() from parsing the entire file.  LoadFromFile() only works
correctly for plain-text files.

> Is there something I have to do different for some files?

Yes - don't use TStringList for what you are trying to do.  Access the file


6. Faster TStringList.LoadFromFile

7. TRichEdit->Lines->LoadFromFile( ) filesize warning...

8. Hidden TPanel does not resize when TImage->Picture->LoadFromFile

Return to c++ builder


Who is online

Users browsing this forum: No registered users and 25 guest