Link to home
Start Free TrialLog in
Avatar of efz
efzFlag for United States of America

asked on

FireMonkey - Using NSFileManager in Free Pascal Compiler

Hello Experts,

When searching for a path in Mac OSX, I was advised to use a FileManager method like URLForDirectory. When I do this for OSX, I reference (in the "uses" statement) the "MacAPI.Foundation module" and it works as expected. Unfortunately, when iOS is the target platform, this doesn’t work in the xcode free pascal compiler. Instead, xcode returns the error: 'Identifier not found "NSFileManager"' together with other errors all of which are related to NSFileManager.

In the "uses" statement, I tried replacing the dot with an underscore like all the other FMX modules do (ie. “MacAPI_Foundation”), but that didn’t work either. I searched the Mac folder where FireMonkey stores all its support PAS files, but nothing looked familiar. When I Googled the problem the search results were not exactly on point. I presume I need to include the correct module in the "uses" statement. Does anyone know the correct corresponding module to place in the "uses" clause when programming for iOS in order to access the path-finding functions?
Avatar of Thommy
Thommy
Flag of Germany image

Have you already tried unit iphoneall...

uses iphoneall,...

Open in new window

Avatar of efz

ASKER

Yes, that didn't work. I ended up finding references to NSFileManager in a ".inc" file, but from my past programming experience I was not familiar with the use of that file type in a Delphi Pascal program.
Have you already tried unit FMX_Platform_iOS?
Avatar of efz

ASKER

The FMX_Platform_iOS module was a good guess, but incorrect. I have since learned that all the iOS units are placed by Embarcadero in the fmi folder. When I searched the text of FMX_Platform_iOS.pas there was no reference to NSFileManager and thus the error. I also searched the text of all the pas units in the fmi folder and likewise there was no reference. Now I'm beginning to think I'm barking up the wrong tree and that iOS may not have provision for direct folder access like OS X and Windows, i.e., the sandbox thing.

I'm reading a book on FireMonkey for iOS by Graeme Chandler that may shed some light on this subject.

The reason I have this question in the first place is because I customarily use a form that dynamically populates with controls that it loads from a file at run time. So, if I can't place the files on an iPad for instance and read them in at run time, my normal technique won't work.
ASKER CERTIFIED SOLUTION
Avatar of Thommy
Thommy
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of efz

ASKER

When I tried adding FMX_Platform_iOS to the uses statement, I never removed iPhoneAll which I had previously tried. So, it's still not resolving the identification error. Also, I noted that there is no error related to the actual insertion of FMX_Platform_iOS and iPhoneAll in the uses clause so the compiler must be finding the units themselves.

I jumped forward to the section of Chandler's book where he mentions NSFileManager, but his examples excerpt code wtihout showing the uses statement. I think there are complete code samples available and I'll check those.
Avatar of efz

ASKER

Thommy,

The Chandler example is using iPhoneAll in the uses clause as you suspected.

I guess my job now will be to find out why I'm getting the error. Again, surprisingly, I'm not getting an error related to iPhoneAll in the uses statement, so that's confusing me. If the compiler's finding iPhoneAll, why isn't able to find the NSFileManager declaration?
Avatar of efz

ASKER

Two things.

One. I found the iPhoneAll.pas file and there is definitely a NSFileManager declaration contained within.

Two. I also located Chandler's demo code. The uses statement reference the iPhoneAll as you correctly suggested, and above the uses statement was the following:

{IFDEF FPC}
{$modeswitch objectivec1}
{$ENDIF FPC}

I included it, but damn if I still didn't get the error "cannot find identifier NSFileManager." I must be living under a cloud.

Any final suggestions before I issue the points to you?
Avatar of efz

ASKER

For interested parties, Thommy's suggestion was spot on.

What continued to cause the error was the fact that the syntax for OS X and iOS was slightly different and because I didn't disclose my code, I wasn't giving Thommy much of a clue. In order to follow up on his advice I located some demo code that is included with Chandler's book (a must-have if you're coming to iOS via FireMonkey) that demonstrated the technique for querying directory paths in iOS.

Thanks Thommy.
I will also have a look at Graeme Chandler's book.

Thank you very much for the points!!!
:o)))