LoadFromFile can't open 'locked' files

I have a small TMemo-based text viewer but I've got a problem when trying to open files that are in use by another application.

I get a "Cannot open file C:\...... The process cannot access the file because it is in use by another process".

I use this function for loading the text:
Memo1->Lines->LoadFromFile(path, encoding);

I can load the file by loading the text by myself using ifstream, but then I miss the convenient unicode support in LoadFromFile.

Anyone know if I can get LoadFromFile to be able to open these "locked" files? Or some workaround? Thanks.
0
Anonymous
1/4/2009 6:56:47 PM
embarcadero.cppbuilder.nontech 971 articles. 0 followers. Follow

7 Replies
1151 Views

Similar Articles

[PageSpeed] 59
Get it on Google Play
Get it on Apple App Store

Hi Anders

Anders Andersson wrote:

> 
> Anyone know if I can get LoadFromFile to be able to open these 
> "locked" files? Or some workaround? Thanks.
> 

You could try

WORD Acces = fmShareDenyNone | fmOpenRead;

std::auto_ptr<TFileStream> FileStrm( new TFileStream(String FileName, Acces) );

and then use 

Memo->LoadFromStream(FileStrm.get());

Kind regards
Asger
0
Asger
1/4/2009 9:25:27 PM
<Anders Andersson> wrote in message news:62573@forums.codegear.com...

> I have a small TMemo-based text viewer but I've got a problem
> when trying to open files that are in use by another application.
>
> I get a "Cannot open file C:\...... The process cannot access the file
> because it is in use by another process".

TStrings.LoadFromFile() uses the fmShareDenyWrite flag internally when 
opening the file.  If the other app has the file opened with GENERIC_WRITE 
access, then LoadFromFile() will fail.

> Anyone know if I can get LoadFromFile to be able to open these
> "locked" files? Or some workaround? Thanks.

As Asger mentioned, you will have to create a separate TFileStream object so 
that you can specify your own access rights a needed, and then use 
LoadFromStream() instead of LoadFromFile().

-- 
Remy Lebeau (TeamB)
0
Remy
1/5/2009 8:31:51 AM
> {quote:title=Asger Joergensen wrote:}{quote}
> You could try
> 
> WORD Acces = fmShareDenyNone | fmOpenRead;
> 
> std::auto_ptr<TFileStream> FileStrm( new TFileStream(String FileName, Acces) );
> 
> and then use 
> 
> Memo->LoadFromStream(FileStrm.get());

Thanks, that was exactly what I was looking for, works perfectly.
0
Anonymous
1/5/2009 1:28:06 PM
"Asger Joergensen" <Junk@Asger-P.dk> schreef in bericht 
news:62592@forums.codegear.com...

> You could try
>
> WORD Acces = fmShareDenyNone | fmOpenRead;
>
> std::auto_ptr<TFileStream> FileStrm( new TFileStream(String FileName, 
> Acces) );
>
> and then use
>
> Memo->LoadFromStream(FileStrm.get());
> Kind regards
> Asger

What does  FileStrm.get() stand for?

Thanks in advance,
Wiebe Vos
0
Wiebe
1/29/2009 6:24:57 PM
Wiebe Vos <wiebe@foxware.nl> wrote:

>> std::auto_ptr<TFileStream> FileStrm( new TFileStream(String FileName, Acces) );

[...]

>What does  FileStrm.get() stand for?

It returns the address of the TFileStream created in the std::auto_ptr<>
constructor call.

If you don't know about the std::auto_ptr<> class template, I'd strongly
suggest going to look at your C++ documentation.

Alan Bellingham
-- 
Team Browns
ACCU Conference 2009: Wed 22 - Sat 25 April 2009, Oxford
0
Alan
1/29/2009 6:29:17 PM
Hi Wiebe

Wiebe Vos wrote:

> "Asger Joergensen" <Junk@Asger-P.dk> schreef in bericht news:62592@forums.codegear.com...
> 
> > You could try
> > 
> > WORD Acces = fmShareDenyNone | fmOpenRead;
> > 
> >std::auto_ptr<TFileStream> FileStrm( new TFileStream(String FileName,  Acces) );
> > 
> > and then use
> > 
> > Memo->LoadFromStream(FileStrm.get());
> > Kind regards
> > Asger
> 
> What does  FileStrm.get() stand for?

FileStrm is actually of type auto_ptr and auto_ptr::get()
gives return a pointer to the object that it created.
You use auto_ptr so that You dont have to wory about deleting
the object (TFileStream in this case) not even when an exception
is thrown.

You can see more in the STL help about auto_ptr.

Kind regards
Asger
0
Asger
1/29/2009 6:33:47 PM
>>What does  FileStrm.get() stand for?
>
> It returns the address of the TFileStream created in the std::auto_ptr<>
> constructor call.
>
> If you don't know about the std::auto_ptr<> class template, I'd strongly
> suggest going to look at your C++ documentation.

Thanks all,
I did not realize that it refers to std::auto_ptr<> class template rather 
than
TFileStream itself.
Wiebe Vos
0
Wiebe
1/30/2009 10:11:28 AM
Reply:

Similar Artilces:

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

'NMDayTim', 'Psock' , 'NMTime' , 'NMFtp' can not be opened.
hello, my colleague have developed an application under c++ builder 5. so now i should undertake it and optimize it. last days i have installed the C++ Builder 2010 testversion to get some experience on it, because i have not used it before. when i try to compile the old project in C++ builder 2010, comes some Compile errors. Also, there are some Includes like 'NMDayTim', 'Psock' , 'NMTime' , 'NMFtp' in this old Project. they can be found and compiled in the old c++ Builder 5. but not in c++ builder 2010. so i want to know do i solve this problem or go...

I can't get no cache, I can't get no cache. 'Cause I try and I try and I try and, I can't get no, I can't get no cache.
I have fiddled out for days tinkering with the setting in about:config trying to get FireFox 12 to use the disk cache. I have NOT found the trick. This One Trick Pony ain't doing it like it used to up until recently. Pray tell anyone, What information can I share that will point a knowledgeable person to aid me in getting FF to disk.cache? I have also tried restarting FF with add-ons disabled, (There were NOT too many to do this to, so it was quick and easy) Here is my stab at trying to convey the information that MIGHT govern matters Using about:cache Informatio...

Re: I can't get no cache, I can't get no cache. ' Cause I try and I try and I try and, I can't get no, I can't get no cache.
<div>please com e see me about htis<br /> <br /> ------- Original Message f= rom the Global Relay Archive -------<br /> From: Hp &lt;ferd@farkel.net&gt;= <br /> To: "support-firefox@lists.mozilla.org" &lt;support-firefox@lists.mo= zilla.org&gt;<br /> Sent: Sun, 27 May 2012 18:30:18 -0700<br /> Subject: I = can't get no cache, I can't get no cache. 'Cause I try and I try and I try = and, I can't get no, I can't get no cache.<br /> <br /></div> <pre class=3D"gr-maex-body-pre&qu...

'Mozilla Composer' on Mac: Won't open html files
Hi. Last night I tried to help my friend install Sea Monkey on his Apple Mac so he can use Mozilla Composer to create and edit html files. We appeared to successfully install Sea Monkey for Mac OS, but when we tried to open a (very, very) simple html file that I had just created in Mozilla Composer on my PC it would not open it. Every time we tried we got a dialog box saying something like: "This is a binary file. Do you want to: (a) Open it; or (b) Save it." -When we clicked on 'Open' we got the usual list of programs, but Mozilla Composer was not one of them. Actual...

Can't open include file 'sqlca.h'.
Hello, I tried to run the embedded SQL in C simple example from the ASA programming Interfaces Guide and I encounter with some problem. The following code is from the document. ------------------------------------------------------------------------ #include <stdio.h> EXEC SQL INCLUDE SQLCA; main() { db_init(&sqlca); EXEC SQL WHENEVER SQLERROR GOTO ERROR; EXEC SQL CONNECT "dba" IDENTIFIED BY "sql"; EXEC SQL UPDATE employee set emp_lname = 'Plankton' where emp_id = 195; EXEC SQL COMMIT WORK; EXEC SQL D...

2010: Can't register - can't download the software - can't register until I have the software
I have active maintenance on Rad Studio: From: Vicky Rassmisaengthong [mailto:Vicky.Rassmisaengthong@EMBARCADERO.COM] Sent: Wednesday, February 25, 2009 1:58 PM To: rgrossman Cc: amer.supportadmin@codegear.com; Ashley Cosentino Subject: Software Assurance Support for Tech III Inc PO# Credit Card Dear Embarcadero Technologies Support Customer, Welcome! You have been registered as the primary contact on support account number AM####### Herewith we confirm your Embarcadero Technologies support agreement covering: Qty 1 RAD Studio Enterprise Named User licens...

Can't open a connection to site '%S_SRVID' because 'set up channel' message was not acknowledged
I'm using Adaptive Server Enterprise/12.5.2/EBF 11798/P/NT (IX86)/OS 4.0/ase1252/1831/32-bit/OPT/Fri Apr 09 04:15:03 2004 This morning the prod db server semi-hung. Although not pinned at 100%, all 4 cpus were constantly above 95% utilization. All application connecting to it became unusable. Killing spids did not help. When I issued a "shutdown <server_name> with nowait" I got the following message back: "Msg 7211, Level 18, State 1 Can't open a connection to site '<server_name>' because 'set up channel' message was not ack...

I can't stop a 'what's new' tab opening
Name: Bradley Crees Product: Shiretoko Summary: I can't stop a 'what's new' tab opening Comments: every time I open firefox it opens a tab with http://en-us.www.mozilla.com/en-US/firefox/3.1b1/whatsnew/ I can't stop it coming up, and it's affecting my ocd Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this feedback but if you wish to provide one you must BCC (not CC) the sender for them to ...

Again with the 'reset' and 'can't be found' stuff...
Name: William Jones Email: jbillyjonesatyahoodotcom Product: Firefox Summary: Again with the 'reset' and 'can't be found' stuff... Comments: Hello Again FireFox, Listen...I'm just a simple guy, a 'dial-up baby boomer' who's had to learn the hard way all the way through. I recently sent a similar e-mail requesting assistance with this ridiculous and incessant 'pop up' that informs me that 'my connection has been reset', and/or, 'a problem locating page'....huh? I was just on the damn thing and even switching from one ...

Can't allocate space for object '' in database 'tempdb',How can I do?
when I run system procedure,I got following messages : Can't allocate space for object '' in database 'tempdb' because the 'system'segment is full. If you ran out of space in syslogs, dump the transaction log. Otherwise, use ALTER DATABASE or sp_extendsegment to increase the size of thesegment. Failed to allocate disk space for a work table in database 'mydb'. You may be able to free up space by using the DUMP TRANsaction command, or you may want to extend the size of the database by using the ALTER DATABASE command. thanks. allan wrot...

WWW::Search::Google-->Service description 'file:' can't be loaded: 404 File `' does not exist
Dear my friends... I tried a simple code like this: ==== #!/usr/bin/perl -w use WWW::Search::Google; $key="ABQIAAAASzVWEo9_PkDjwjTkhPHJIxTovFWtVmuuMSRYt_dv3iXA1zQ3OxT9hxr3F7hqD-SZIzQb7p0QjzUobQ"; my $search = WWW::Search->new('Google', key => $key); $search->native_query("Business Education"); while (my $result = $search->next_result()) { print $result->title, "\n"; print $result->url, "\n"; print $result->description, "\n"; print "\n"; } ==== But as I run this ...

Web resources about - LoadFromFile can't open 'locked' files - embarcadero.cppbuilder.nontech

Resources last updated: 12/24/2015 1:41:45 AM