Saving Styled text to Binary File 
Author Message
 Saving Styled text to Binary File

I have a EditField in a global floating window and I have a save function:

dim f as folderItem
dim b as binarystream
f = PreferencesFolder.child("Floatpad Prefs")
If f.exists then
b = f.openasbinaryfile(true)
else
b = f.createbinaryfile("pref")
end if
If  b <> nil then
b.length = 0
b.writelong Notes.left
b.writelong Notes.top
b.writelong Notes.width
b.writelong Notes.height
b.writepstring Notes.title
b.writepstring Notes.EditField1.text
b.writepstring Notes.EditField1.textstyledata
b.close
Notes.TextHasChanged = false
end if

which saves all text in the edit fine. But then when I go to open the file:

dim m as menuItem
dim i as integer
dim f as folderItem
dim b as binarystream
dim s, t as string
f = PreferencesFolder.child("Floatpad Prefs")
If f.exists then
b = f.openasbinaryfile(false)
Notes.left = b.readlong
Notes.top = b.readlong
Notes.width = b.readlong
Notes.height = b.readlong
Notes.title = b.readpstring
t = b.readpstring
s = b.readpstring
Notes.EditField1.settextandstyle t, s
b.close
else
Notes.left = 9
Notes.top = 41
end if
Notes.TextHasChanged = false

It only opens 255 characters of the text saved, then I go to look at the
file and find that is also has 255 characters but I looked at the files
before and it had all the text saved. Does anyone have any ideas why?

Chris



Tue, 24 Jun 2003 02:50:01 GMT  
 Saving Styled text to Binary File

Quote:

> It only opens 255 characters of the text saved, then I go to look at the
> file and find that is also has 255 characters but I looked at the files
> before and it had all the text saved. Does anyone have any ideas why?

writepstring and readpstring are limited to 255 chars.
Save the length yourself with writelong and save the string using write
only.

Mfg
Christian

--
The world will end in 5 minutes.  Please log out.

http://www.christians-software.de (Free Mac/Win software)



Tue, 24 Jun 2003 03:06:05 GMT  
 Saving Styled text to Binary File


Quote:

>> It only opens 255 characters of the text saved, then I go to look at the
>> file and find that is also has 255 characters but I looked at the files
>> before and it had all the text saved. Does anyone have any ideas why?

> writepstring and readpstring are limited to 255 chars.
> Save the length yourself with writelong and save the string using write
> only.

> Mfg
> Christian

Do you have any code to help me as i'm not sure how to code this.

Chris Willis
--------------------------------------------

--------------------------------------------



Tue, 24 Jun 2003 03:44:40 GMT  
 Saving Styled text to Binary File

Quote:

> Do you have any code to help me as i'm not sure how to code this.

Save:

binstream.writelong len(text)
binstream.write text

Load:
i=binstream.readlong
text=binstream.read(i)

Mfg
Christian

--
Spiel des Lebens 3.0 ist fertig!
Die englische Version ist auch schon in Arbeit!

http://www.christians-software.de (Kostenlose Mac/Win Software)



Tue, 24 Jun 2003 05:07:13 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Open and Save Styled Text

2. Saving an Open excel file as a text file

3. Saving Binary Files

4. Saving a binary file

5. Fast Binary File Saving

6. Data saving/loading and binary file format

7. Save data from Fortran in a binary file

8. code style/efficiency question: text file templates

9. Can Tcl(Windows) write unix style text files?

10. ?-Save selected Record as text file.

11. How to save Object Instances in text File ?

12. Saving a Field to a Text File

 

 
Powered by phpBB® Forum Software