Rapid-Q Documentation by William Yu (c)1999 Appendix A: QMEMORYSTREAM


QMEMORYSTREAM Компонент

QMemorystream is used to store temporary data to memory for manipulation.

QMemorystream Свойства
ПолеТипR/WПо умолчаниюПоддерживается





LineCountINTEGERRW
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.
PointerINTEGERRWXG
Pointer specifies the memory address of the memorystream.
PositionINTEGERRWWXG
Position specifies the current position of the memory pointer, any read/write operations will begin from here.
SizeINTEGERRWWXG
Size determines the number of bytes allocated to the memorystream.


QMemorystream Методы
МетодТип ОписаниеПараметры Поддерживается





CloseSUB Close the stream0 WXG
CopyFrom SUB (Stream, Bytes%)Copy from another stream
Either QFileStream or QMemoryStream
2WXG
Use CopyFrom to copy a QFILESTREAM or a QMEMORYSTREAM to the current memorystream.
Детали:
If Bytes% = 0 then the Stream is reset to position 0 and the whole stream is then copied.
Пример:
$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 LONG)Extract resource to memorystream 1WXG
Extracts a resource from your program to the memorystream.
Детали:
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.
Пример (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(), NumElements&)Load data into array 2WXG
MemCopyFrom SUB (Address&, Bytes&)Copies contents of Address& to memorystream 2WXG
MemCopyTo SUB (Address&, Bytes&)Copies contents to Address& 2WXG
ReadSUB (variable) Generic Read, determines the storage space and saves data in variable 1WXG
ReadLineFUNCTION () AS STRING Reads an entire line0 W
ReadNumFUNCTION (Num_Type) AS DOUBLE Возвращает number  -- ie. PRINT File.ReadNum(Num_SINGLE)
Num_Type can be next
CONST Num_BYTE = 1
CONST Num_SHORT = 2
CONST Num_WORD = 3
CONST Num_LONG = 4
CONST Num_DWORD = 5
CONST Num_SINGLE = 6
CONST Num_DOUBLE = 8
1WXG
ReadStrFUNCTION (n) AS STRING Read n bytes, returns the string1 WXG
ReadBinStr FUNCTION (n) AS STRINGRead n bytes, returns the binary string 1W
ReadUDTSUB (MyType) Read and store data in a MyType structure 1WXG
SaveArray SUB (Array(), NumElements&)Save array 2WXG
SeekSUB (Position%, From%) Seek to Position%, From% see RAPIDQ.INC 2WXG
WriteSUB (variable) Generic Write, determines the storage space and saves data to memory 1WXG
WriteLine SUB (S AS STRING)Writes string with CR+LF 1W
WriteNumSUB (number, bytes%) Writes a number to memory2 WXG
WriteBinStr SUB (string, bytes%)Writes a binary string to file (slow) 2W
WriteStrSUB (string, bytes%) Writes string to memory2 WXG
WriteUDTSUB (MyType) Write data stored in a MyType structure 1WXG


QMemoryStream Примеры
  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)

Предыдущий Компонент Содержание Следующий Компонент