' Rapid-Q by William Yu (c)1999-2000 . ' ================================================================================ ' Upload_il_tuo_script_su_Rapidq.it ' Qmemorystream ****** QMEMORYSTREAM Component ****** QMemorystream is used to store temporary data to memory for manipulation. QMemorystream Properties Field Type R/W Default Support =============== =============== =============== =============== =============== LineCount INTEGER R W LineCount determines how many lines there are in the memorystream. Note that LineCount ignores the CR character, and will only detect LF, so it treats CRLF as one line, but LFLF as 2 lines. Pointer INTEGER R WXG Pointer specifies the memory address of the memorystream. Position INTEGER RW WXG Position specifies the current position of the memory pointer, any read/write operations will begin from here. Size INTEGER RW WXG Size determines the number of bytes allocated to the memorystream. QMemorystream Methods Method Type Description Params Support ============== ================= ============== =============== =============== Close SUB Close the 0 WXG stream CopyFrom SUB (Stream, Copy from 2 WXG Bytes%) another stream Either QFileStream or QMemoryStream Use CopyFrom to copy a QFILESTREAM or a QMEMORYSTREAM to the current memorystream. Details: If Bytes% = 0 then the Stream is reset to position 0 and the whole stream is then copied. Example: $INCLUDE "RAPIDQ.INC" DIM File1 AS QFILESTREAM DIM Mem AS QMEMORYSTREAM File1.Open("test.txt", fmOpenRead) Mem.CopyFrom(File1, 123) '-- Copy 123 bytes from File1 ExtractRes SUB (Resource AS Extract 1 WXG LONG) resource to memorystream Extracts a resource from your program to the memorystream. Details: The parameter Resource is not the resource handle, but the absolute position of the resource within your file. This requires that you use the keyword Resource(n) to specify the resource number. Example_(dumping_all_resources): $INCLUDE "RAPIDQ.INC" $RESOURCE res_1 as "res.1" $RESOURCE res_2 as "res.2" DIM Mem AS QMEMORYSTREAM FOR I = 0 TO ResourceCount-1 Mem.ExtractRes(Resource(I)) NEXT LoadArray SUB (Array(), Load data into 2 WXG NumElements&) array MemCopyFrom SUB Copies 2 WXG (Address&, contents of Bytes&) Address& to memorystream MemCopyTo SUB Copies 2 WXG (Address&, contents to Bytes&) Address& Read SUB (variable) Generic Read, 1 WXG determines the storage space and saves data in variable ReadLine FUNCTION () AS Reads an 0 W STRING entire line ReadNum FUNCTION (n) AS Read n bytes, 1 WXG DOUBLE returns number ReadStr FUNCTION (n) AS Read n bytes, 1 WXG STRING returns the string ReadBinStr FUNCTION (n) AS Read n bytes, 1 W STRING returns the binary string ReadUDT SUB (MyType) Read and store 1 WXG data in a MyType structure SaveArray SUB (Array(), Save array 2 WXG NumElements&) Seek SUB (Position%, Seek to 2 WXG From%) Position%, From% see RAPIDQ.INC Write SUB (variable) Generic Write, 1 WXG determines the storage space and saves data to memory WriteLine SUB (S AS STRING) Writes string 1 W with CR+LF WriteNum SUB (number, Writes a 2 WXG bytes%) number to memory WriteBinStr SUB (string, Writes a 2 W bytes%) binary string to file (slow) WriteStr SUB (string, Writes string 2 WXG bytes%) to memory WriteUDT SUB (MyType) Write data 1 WXG stored in a MyType structure QMemoryStream Examples DIM Mem AS QMemoryStream S$ = "Hello world!" Mem.WriteStr(S$, LEN(S$)) Mem.Position = 0 S$ = Mem.ReadStr(LEN(S$)) PRINT S$ '' print it Mem.Close '------------------------------------------------------ DIM Mem AS QMemoryStream DIM I AS INTEGER I = 12 Mem.Write(I) S$ = "Hello world!" Mem.Write(S$) Mem.Position = 0 Mem.Read(I) S$ = SPACE$(I) Mem.Read(S$) PRINT S$ '' print it Mem.Close '------------------------------------------------------ TYPE MyType Name AS STRING*30 Phone AS STRING*8 Age AS INTEGER END TYPE DIM Person AS MyType Person.Name = "Joe" Person.Phone = "555-5555" DIM Mem AS QMemoryStream Mem.WriteUDT(Person) ' =============================================================================== ' 2003 Holyguard.net - 2007_Abruzzoweb