image ResEx Logo
ResExcellence www : Powered by Google
Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Articles
   3D
   Audio
   Custom Controls
   General RB
   Graphics
   Hacks
   Mac OS X
   Menus
   Novelty
   Printing
   REALbasic 2005
   REALbasic 2006
   Registration
   Resources
   Reviews
   Serial
   Speech
   Sockets
   XML
   Video
Resource Links
News
   Current News
   February 2006
   January 2006
   December 2005
   November 2005
   October 2005
   September 2005
   August 2005
   July 2005
   June 2005
   May 2005
   April 2005
   March 2005









REALbasic for Dummies
by Erick Tejkowski


Learning REALbasic through Applications
by Clayton E., Crooks II


REALbasic for Macintosh
by Michael Swaine


REALbasic Cross-Platform Application Development
by Mark S. Choate





Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander
Tell us about a bad link. Thank You!

Virtual Volumes by Erick Tejkowsi
08-01-02

Printer Version




V DRIVE To continue our examinination of the new features in REALbasic 4.5, we'll look at Virtual Volumes this week. If you've ever needed to store different kinds of data in one file, REALbasic's Virtual Volumes are for you!


NOTE: This project requires REALbasic 4.5 or newer!

The new VirtualVolume feature of REALbasic is easy to learn, quick to code, and is a pretty handy tool for your next REALbasic project. The VirtualVolume class lets you store multiple files in one file. This is somewhat like the disk images that you may have used in the Finder. Since REALbasic 4.5 gives you this feature across all of its target platforms (OS9, OSX, and Win32), we'll build today's example using the Classic Mac OS.

Build the Interface

Launch REALbasic and open Window1 from the Project window. To this window, add the following controls:

Control Type Control Name Other Properties
PushButton PushButton1  
PushButton PushButton2  
EditField EditField1 ReadOnly=TRUE
EditField EditField2 ReadOnly=TRUE

Arrange the interface however you want. It might look like this:

08-01-02_interface.jpg (20k)

Source Code

That's it for the interface, now it's time to add some code. The code we'll add goes in the Action event of PushButton1 and PushButton2. First, PushButton1:

  dim f,root,textfile,numberfile as folderItem 
  dim v as virtualVolume
  dim textout as textoutputStream
  dim numout as binaryStream
  dim d as date 
  
  f=DesktopFolder.Child("Resex Virtual Volume")
  v=f.createVirtualVolume
  
  if v<>nil then
    //we have a virtual volme, so let's find it's root
    root = v.Root
    
    //create folderitems for the items
    //we will add to the virtual volume
    textfile = root.child("My Text")
    numberfile = root.child("My Date")
    
    if textfile<>nil then
      //create a text file on the virtual volume
      textout = textfile.createTextFile
      //add some text to it
      textout.writeline "This is text on my virtual volume."
      textout.close
    end if
    
    if numberfile<>nil then
      d=new date 
      //using a generic binary file type here
      //that we didn't even have to define
      //in the file types dialog
      numout = numberfile.createbinaryFile("")
      //store the day, month, and year
      numout.writelong d.day 
      numout.writelong d.month 
      numout.writelong d.Year
      numout.close
    end if
    
  end if
  

Then, it's time for PushButton2

  dim f,root,textfile,numfile as folderItem 
  dim v as virtualVolume
  dim textin as textinputStream
  dim binin as binaryStream
  dim s as string 
  
  f=DesktopFolder.Child("Resex Virtual Volume")
  
  //now open the virtual volume
  v=f.OpenAsVirtualVolume
  
  if v<>nil then
    //we have a virtual volme, so let's find it's root
    root = v.Root
    
    //create folderitems for the items
    //we will retrieve from the virtual volume
    textfile = root.child("My Text")
    numfile = root.child("My Date")
    
    if textfile<>nil and textfile.exists then
      //create a text file on the virtual volume
      textin = textfile.openasTextFile
      //read the text from it
      editfield1.text=textin.readline
      textin.close
    end if
    
    if numfile<>nil and numfile.exists  then
      //get the date from the virtual volume
      binin = numfile.openasbinaryFile(FALSE)
      if binin<>nil then
        //day
        s = str(binin.readlong)+"."
        //month
        s = s + str(binin.readlong)+"."
        //year
        s = s + str(binin.readlong)
        editfield2.text=s 
        binin.close
      end if
      
    end if
    
  end if
  

As you can tell, there isn't much to learn here, but there is much to gain. Creating a VirtualVolume requires use of the new "CreateVirtualVolume" method of the FolderItem class. Once you have a VirtualVolume, you find it's root using the "Root" method. From there, it's standard REALbasic code.

Conclusion

To test the project, select the Debug-Run menu. The demo creates a VirtualVolume on the desktop and adds two files to it. Clicking the other PushButton will retrieve the data from the VirtualVolume. As usual you can download the completed project instead of creating it by hand. Use your imagination when playing with the new VirtualVolume features of REALbasic 4.5. There are many useful possibilities for using this feature:

  • As a kind of "virtual" resource fork
  • As a way to package your favorite skins in one file
  • As a database
  • As an archive for easy one-file backups
The cool part about the VirtualVolume is that you don't have to create your own weird file formats. You can put information together into one file using the standard text and binary file operations that you already know. Neat! Have fun and see you next week!



Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement. [an error occurred while processing this directive]