TStringList->LoadFromFile throws exception

c++ builder

    Sponsored Links

    Next

  • 1. getdate
    struct date d; getdate(&d); Edit2->SelText=String(d.da_year)+":"+String(d.da_mon)+":"+String(d.da_day); the result is 2006: : what's wrong? thanks.
  • 2. Using third party bcb6 vcl's with bds
    Hi, I am testing the bds evaluation version. I have spent some time looking into the possibility of using vcl components compiled for bcb6 with bds. My main problem appears to be the lack of rtl60.bpl. I have read that the updates to bds include rtl60.bpl. Does that mean that I will be able to work with my old components in bds if I purchase the full version and install the updates? I don't have access to the full source for the components so recompiling them to work with bds is not an option AFAICT. Ideally I would prefer to purchase bds than bcb6 as I have read there are several bug fixes for the gui and it is generally easier to work with. Either way I have to purchase the compiler so what is the recommendation? Cheers. Patrick
  • 3. Serial Communication
    Windows GUI serial communication example using Borland's new Turbo C++ Explorer. Ideas can be applied to older versions of C++ Builder too. turboc.simpleserial.com
  • 4. This is a New Question
    Hans or JD or whoever. I've found and gone over my other earlier program and find that I used One Label to do the work of an TEdit and that it's work would place text into the Label I wanted it to go. Now I've just done an experiment and found that if I make the caption of e.g. label1 as 45 and putting experimental text into the Open Venture file this number will appear in Label2. I need to learn the right code to go on though. Has anyone actually tried this type? I apparently used several labels to invoke the answers into paralell labels and the figures are very accurate though I have to add the one item first into the three Tedit boxes that are used to enter the calculations for the program. Hope I haven't mixed this too much. Has anyone any code that might work this way. I imagine I devided TEdit 2 by TEdit3 and used TEdit1 for the Kilometer work which all came out in the different labels with all the coding done inside the labesl as I've been working with the TEdit's. Verne
  • 5. SpinEdit giving EConvertError Exception
    I am having trouble accessing the Value of a TCSpinEdit component (from Samples tab) when in the OnChange event. If I use the up/down buttons to change the Value everything seems ok. But if I select the existing value in the edit box and type a new (valid) value then as soon as I read the CSpinEdit1->Value I get an exception message EConvertError saying ""is not a valid Integer value. I get this even with the following code void __fastcall TForm1::CSpinEdit1Change(TObject *Sender) { int i = CSpinEdit1->Value; } Am I doing something silly ? or is this a fault ? I suspect the event is being triggered when the original data is cleared internally but before the newly typed data has been loaded, if so then there is no valid data at that time. Any suggestions? John Mulvey

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?

matus 



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 | 
fmShareDenyNone);
    try
    {
        Strings->LoadFromStream(Stream);
    }
    __finally
    {
        delete Stream;
    }


Gambit 



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
 http://www.**--****.com/  



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.

  Regards,
    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
solving.

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
  begin
    FillRect(Rect);
     If Not FileExists(myListbox.Items[Index]) Then Exit;
        Bitmap:=TBitmap.Create;
        if Bitmap<>nil then
        begin
          //
          // Bitmap.PixelFormat := pf24bit; //tryed setting this..it
          // didnt help
          //
          Bitmap.LoadFromFile( myListbox.Items[Index] ); 
           R:=Bounds(
              Rect.Left+10,
              Rect.Top+4,
              Round(100*BitRatio),
              Rect.Bottom-Rect.top-2);
          StretchDraw(R,Bitmap);
          Bitmap.Free;
     end;
   end;
...

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
directly.


Gambit


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 39 guest