comDoc

Share your advanced PureBasic knowledge/code with the community.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: comDoc

Post by srod »

SFSxOI wrote:@srod

When you say "any number of disparate 'files' " - do you mean documents only or files of any type?

Looks good and I can see the your touch of excellance in this product, thank you very much :)
A single document (in the comDoc) sense is a single object residing either in memory or within a single disc file. Into this document you can create any number of files; each of which you give a name (e.g. "file1", "image1",... etc.) and you will then typically end up with a single disc file containing this collection of files.

When you subsequently open one of these documents (with one of comDoc's document creation functions) you can then open any (or all) of the 'files' contained within and access that file just as if it was a disc file all of it's own (which it is not!)

For example, here is one of the demo programs which opens a document which I created in another demo. The document sits in a disc file with the name "test.cmp" and inside this one document I created two files; "file1" in which I wrote 1000 longs and "file2" in which I wrote a couple of utf-8 strings. See how the demo opens the document and then accesses these two files.

Code: Select all

CoInitialize_(0)

XIncludeFile "..\comDoc.pbi"

Define myDoc.comDocDocumentObject, myFile.comDocFileObject

;Open our disc-based compound document.
  myDoc = comDoc_OpenDiscDocument("test.cmp")

If myDoc
  ;Open the first file which we named "file1"
    myFile = myDoc\OpenFile("file1")
    If myfile
      Debug "'file1'..."
      ;Read all the longs we wrote to this file.
       While myfile\Eof() = 0
          Debug "    " + Str(myFile\ReadLong())
        Wend
      myFile\Close()
    EndIf
    Debug "====="
  ;The second file which we named "file2"
    myFile = myDoc\OpenFile("file2")
    If myfile
      Debug "'file2'..."
      ;Read all the strings we wrote to this file.
        While myfile\Eof() = 0
          Debug "    " + myFile\ReadString(#PB_UTF8)
        Wend
      myFile\Close()
    EndIf
  myDoc\Close()
EndIf
MS Word saves documents (.doc, not .docx) in this kind of format. A .doc file is basically a compound file and you can open one with one of my demos if you wish and take a look inside. :)

I hope that answers your question?
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: comDoc

Post by srod »

comDoc 1.2 - 22nd Apr 2010.

Version 1.2 fixes a memory leak.
I may look like a mule, but I'm not a complete ass.
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: comDoc

Post by Perkin »

Nice srod, this will be very useful.
Many Thanks.
%101010 = $2A = 42
Perkin
Enthusiast
Enthusiast
Posts: 504
Joined: Thu Jul 03, 2008 10:13 pm
Location: Kent, UK

Re: comDoc

Post by Perkin »

On your comDoc page of your website, the link highlighted 'comDoc' in the first paragraph links to scintilla.
%101010 = $2A = 42
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: comDoc

Post by srod »

Perkin wrote:On your comDoc page of your website, the link highlighted 'comDoc' in the first paragraph links to scintilla.
And why not! I was going to link it to a porn site, but thought better of it in the end! :wink:

Doh!!!
I may look like a mule, but I'm not a complete ass.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: comDoc

Post by SFSxOI »

srod wrote:
SFSxOI wrote:@srod

When you say "any number of disparate 'files' " - do you mean documents only or files of any type?

Looks good and I can see the your touch of excellance in this product, thank you very much :)
A single document (in the comDoc) sense is a single object residing either in memory or within a single disc file. Into this document you can create any number of files; each of which you give a name (e.g. "file1", "image1",... etc.) and you will then typically end up with a single disc file containing this collection of files.

When you subsequently open one of these documents (with one of comDoc's document creation functions) you can then open any (or all) of the 'files' contained within and access that file just as if it was a disc file all of it's own (which it is not!)

For example, here is one of the demo programs which opens a document which I created in another demo. The document sits in a disc file with the name "test.cmp" and inside this one document I created two files; "file1" in which I wrote 1000 longs and "file2" in which I wrote a couple of utf-8 strings. See how the demo opens the document and then accesses these two files.

Code: Select all

CoInitialize_(0)

XIncludeFile "..\comDoc.pbi"

Define myDoc.comDocDocumentObject, myFile.comDocFileObject

;Open our disc-based compound document.
  myDoc = comDoc_OpenDiscDocument("test.cmp")

If myDoc
  ;Open the first file which we named "file1"
    myFile = myDoc\OpenFile("file1")
    If myfile
      Debug "'file1'..."
      ;Read all the longs we wrote to this file.
       While myfile\Eof() = 0
          Debug "    " + Str(myFile\ReadLong())
        Wend
      myFile\Close()
    EndIf
    Debug "====="
  ;The second file which we named "file2"
    myFile = myDoc\OpenFile("file2")
    If myfile
      Debug "'file2'..."
      ;Read all the strings we wrote to this file.
        While myfile\Eof() = 0
          Debug "    " + myFile\ReadString(#PB_UTF8)
        Wend
      myFile\Close()
    EndIf
  myDoc\Close()
EndIf
MS Word saves documents (.doc, not .docx) in this kind of format. A .doc file is basically a compound file and you can open one with one of my demos if you wish and take a look inside. :)

I hope that answers your question?

Yep it does answer my question. Thank You very much :)
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: comDoc

Post by srod »

comDoc 1.3 - 23nd Apr 2010.

Version 1.3 fixes a \ReadString() problem (Unicode destroyed it!)
I may look like a mule, but I'm not a complete ass.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: comDoc

Post by ts-soft »

If i delete some files in a document the document wasn't smaller.
Is there a way to "compress" the document? Or have i to recreate the file?

Greetings
Thomas
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: comDoc

Post by Josh »

try to save with a other filename
Last edited by Josh on Sun Apr 29, 2012 8:03 am, edited 1 time in total.
sorry for my bad english
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: comDoc

Post by ts-soft »

Josh wrote:try to save with a other filename
look here
:D thx, i will test it

// edit
works fine!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: comDoc

Post by srod »

Yes it is undoubtedly a fragmentation problem. Saving to a new file works fine here.
I may look like a mule, but I'm not a complete ass.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: comDoc

Post by Kwai chang caine »

I probably put as much time to understand what is the function of your code, that you, for create it :oops:
And i have finally understand...and I do not regret having tried to find :wink:

Since all this years of hard works for this forum, you heard surely so much compliments about all your enormous codes.....
Hhuuuuummmmffff !!!! ......that what i can say more ???? :roll:

Just perhaps one thing....that this forum would be without you ???
It's the right hand on the heart, and a little tear in the eye, that i write that 8)

Thanks for this great idea who, like comate, will boost even more, our love PB, at the side of his great brothers languages.

When a day, i go in the sky.......i can say at the doorman :

"Hello....it's just a little KCC who knocking at the door.... :oops:"
I'm nothing....but when even, i'm a big personality on the earth.....
Because me....little KCC...i know, and have talking numerous time, with SROD and other gods like FRED, NETMAESTRO, SPARKIE, GNOZAL....and more and more great persons 8)
And further more...i'm the personally IDIOT of one of his GODS :mrgreen:

See the proof, this is my card :

Image

And i'm sure the portman say to me, in the same time he open the door at the maximum, and greets me :
"So, you already know as much gods :shock: :shock:,
Then welcome in the paradise..."
Image

Thank you very much to exist ......MASTER 8)
And again thanks for this usefull code
ImageThe happiness is a road...
Not a destination
shire
User
User
Posts: 46
Joined: Mon Jul 25, 2011 5:24 am

Re: comDoc

Post by shire »

Hello,

This seems good, where could I download it?

Thank you.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: comDoc

Post by Kwai chang caine »

On the site of SROD, but for the time it is down :(
http://www.nxsoftware.com/

This thread talk about that
http://www.purebasic.fr/english/viewtop ... 88#p372188
ImageThe happiness is a road...
Not a destination
shire
User
User
Posts: 46
Joined: Mon Jul 25, 2011 5:24 am

Re: comDoc

Post by shire »

@Kwaï chang caïne:

Tnx for the info.

Too bad I can't download it :(
Post Reply