Posted by webmaster Guido on April 07, 2009
In Reply to TWebBrowser & WinWord posted by Giovanni Caramia p12316 on April 06, 2009
: I have used TWebBrowser in application for documents preview (.doc .xls).
: Code:
: WebBrowser1.Navigate('path+filename.doc');
: When one document is opened from 2 or more users, often
my application works fine on the 1th user but freezes on the others.
: So i'm looking for:
: - some code (if any exists) that can open these documents in read-only mode
: or
: - any idea to solve the iusse.
This is not a Delphi related issue, this is typical behaviour of the MS Office programs (Word, Excel,...). When a document is opened a second time, you won't see another copy of it but you stay with the firstly opened one.
To see what happens, try this: double click on a .doc file in your file manager (Windows Explorer or similar), and MS Word will start and load that doc. Next double click again on that same doc in your file manager... and nothing will happen.
You can't change this behaviour by opening the same document twice as "read only". And changing the file's properties to "read only" with the file manager doesn't help either.
So the only work around that I see is: your application copies the wanted file under a *unique* name, for example to the same directory as where the application is located on disk. Next, it loads that copy into the WebBrowser. After previewing, your application should delete the copy.
Tip: here's a quick and dirty code example for generating a random unique filename:
function UniqueFileName(Extension: string): string;
// Extension can be .doc or .xls or whatever
var
i: integer;
begin
repeat
Result := ExtractFilePath(Application.ExeName);
for i := 1 to 3 do
Result := Result + IntToStr(Random(9));
Result := Result + '.doc';
until not FileExists(Result);
end;
Related articles
DelphiLand Club members: enter your Membership password.
Guests can get a Forum Guest password by subscribing to the DelphiLand Newsletter.
Special Internet Offer for ZoneAlarm Antivirus Protection - Click here!