Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: File only visible after close+restart of app


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 3 - Last Post: Aug 15, 2017 9:17 AM Last Post By: Chris Dunn
Steph van Hooft

Posts: 3
Registered: 4/18/02
File only visible after close+restart of app  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 5, 2017 6:55 AM
Hi,

Delphi 10.2, iOS with iPad and iPhone 6S 10.3.2.

My app downloads a file and saves it, it then tries to show the file in a TWebBrowser component.
This gives the exception 'The specified file was not found' raised in TCommonWebBrowserService.DoNavigate.

Weird thing is that FileExists() returns True, and if I close and reopen the app then the file is visible (if I look with TNSBundle.pathsForResourcesOfType)

I tried saving the files in different ways:
* with TFileStream, with different parameters
* with TNSFileManager.createFileAtPath
* with TNSFileHandle.writeData

But nothing seems to work. If the file doesn't exists when I write to the disk, then the file is not visible until I restart the app.

Has anybody seen this before, or does anybody know what is happening?
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: File only visible after close+restart of app  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 5, 2017 2:20 PM   in response to: Steph van Hooft in response to: Steph van Hooft
Steph van Hooft wrote:

Has anybody seen this before, or does anybody know what is happening?

Can you provide a reproducible example, or at least the steps to do so?

--
Dave Nottage [MVP, TeamB]
Find hints, tips and tricks at Delphi Worlds blog: http://www.delphiworlds.com
Steph van Hooft

Posts: 3
Registered: 4/18/02
Re: File only visible after close+restart of app  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 6, 2017 12:59 AM   in response to: Dave Nottage in response to: Dave Nottage
procedure Test;
var
  Dir, Name: string;
  FileName: string;
  Guid: TGuid;
  SS: TStringList;
 
  LDir: string;
  LPath: NSString;
  Bundle: Pointer;
  LFileName: string;
begin
  Dir := TPath.GetTempPath;
  // unique name, so it is a new file
  CreateGUID(Guid);
  Name := GuidToString(Guid).Replace('{', '').Replace('}', '').Replace('-', '');
  Name := Name + '.txt';
 
  FileName := TPath.Combine(Dir, Name);
 
  // create file
  SS := TStringList.Create;
  try
    SS.Add('test');
    SS.SaveToFile(FileName);
  finally
    SS.Free;
  end;
 
  // check if file exists
  if not FileExists(FileName) then
    raise Exception.CreateFmt('FileExists: File %s does not exists', [FileName]);
 
  // same code as TCommonWebBrowserService.DoNavigate
  LDir := ExtractFileDir(FileName);
  Bundle := TNSBundle.OCClass.bundleWithPath(StrToNSStr(LDir));
  LFileName := ExtractFileName(FileName);
  LPath := TNSBundle.Wrap(Bundle).pathForResource(StrToNSStr(LFileName), nil);
  if LPath = nil then
    raise Exception.CreateFmt('Bundle: File %s does not exists', [FileName]);
end;

If I call this procedure twice, then it fails at the bundle check.
Chris Dunn

Posts: 160
Registered: 8/22/11
Re: File only visible after close+restart of app  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 15, 2017 9:17 AM   in response to: Steph van Hooft in response to: Steph van Hooft
what happens if you create your web browser after you download the file?
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02