|Type||Topic||Plugin||Version||macOS||Windows||Linux||Console & Web||iOS|
|class||Alias||MBS MacClassic Plugin||Yes||No||No||Yes, macOS only||No|
// Store the reference to a FolderItem in a Binary File
Dim alias as MacAliasMBS
dim t,f as FolderItem
Dim bf as BinaryStream, s as String
bf = t.CreateBinaryFile("") // open your binary file here
f = SpecialFolder.Desktop // the FolderItem you want to save
alias = new MacAliasMBS
if alias.Create(nil, f) = 0 then
s = alias.GetRecord
bf.WriteLong LenB(s) // this saves the length of the record
bf.Write s // this saves the record itself
// Retrieve the reference to a FolderItem from a Binary File
dim l as Integer
bf = t.OpenAsBinaryFile(false) // open your binary file here
alias = new MacAliasMBS
l = bf.ReadLong
f = alias.Resolve(nil, alias.attemptMount)
if alias.needsUpdate then
if alias.Update(nil, f) = 1 then
// ... you might want to save the updated alias in your file here
// f now describes the FolderItem again.
// It may not be existing any more, however, so here's a check for that:
if not f.exists then
msgBox "oops! the file is not available any more. Select a new one, please"
//... let the user locate the file
This Plugin implements a new Class for handling Mac OS Alias Records.
AliasRecords are like FolderItems, but can be made persistent: You can convert a FolderItem into a AliasRecord and store that AliasRecord in a file (like your Preferences file). Later you can retrieve that information again and convert it back into a FolderItem.
AliasRecords also appear inside Alias Files, that are usually created by the Finder. The enclosed sample application (Alias Mgr Plugin Demo.π) shows how to create and resolve such Alias Files.
Additional Background Information
The purpose of the class is to store paths to files and/or folders between runs of a RB application.
To store a path to a file/folder in an RB app, currently your only option is to get the abolute path as a string, and store that string in a file, usually your preferences file.
However, there is problem with using this technique: If, between runs of your app, the user changes the path of the file by moving it, or by renaming the file or any of its parent folders (including the volume name), your app will fail to locate the file next time
it is looking for it.
Fortunately, at least in Mac OS, there is a solution to this, which helps you to track your files in such a case. This is done by using Alias Records: they are the basic data structure that is also used in Alias Files as created and used in the Finder.
This class attempts to give the flexibility of Alias Records to your RB apps.
The meaning of the Relative path
When no relative path is specified, then the file is only located by its folder hierarchy down to the root of the volume. However, if a relative path is given, then the file is optionally located relative to that point.
So, if you locate files relatively to some folder, like the folder your application is in, you should specify your app's folder as the relative path so that the target is even found easily when the user moved the whole folder including your app and its related files. This is even more important when using this Alias class under Windows than under Mac OS (if files are moved in Mac OS, they often still can be found even without the help of the original folder hierarchy, while this is not possible under Windows 9x).
For Mac OS X 10.6 or newer, please also check CFBookmarkMBS module.
- property needsUpdate as boolean
- 14 methods
- method AliasInfo as AliasInfoMBS
- method close
- method Create(relPath as FolderItem, target as FolderItem, isDirectory as boolean = false) as Integer
- method CreateAliasFromPath(targetPath as string, fromFilePath as String = "", isDirectory as boolean = false) as Integer
- method CreateFSRef(relPath as memoryblock, target as memoryblock) as Integer
- method CreateMinimal(target as FolderItem, isDirectory as boolean = false) as Integer
- method CreateMinimalFSRef(target as memoryblock) as Integer
- method GetRecord as String
- method PathString as String
- method Resolve(relPath as FolderItem, mode as Integer) as FolderItem
- method SetRecord(record as String)
- method TargetName as String
- method Update(relPath as FolderItem, target as FolderItem) as Integer
- method VolumeName as String
- 12 constants
This class has no sub classes.
Some examples which use this class:
- MBS Xojo / Real Studio Plugins, version 16.0pr7
- MonkeyBread Software Releases the MBS Real Studio plug-ins in version 13.1
- MBS Real Studio Plugins, version 13.1pr12
The items on this page are in the following plugins: MBS MacClassic Plugin.
MBS FileMaker Plugins