Guidance
指路人
g.yi.org
software / RapidQ / RQ Doc / html / qfilestream.html

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

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


QFILESTREAM Component

QFilestream is Rapid-Q's way of handling files. It's more elegant than the GET, and PUT method of traditional BASIC.

QFilestream Properties
FieldTypeR/WDefaultSupport





EOFINTEGERRWXG
EOF specifies whether the file pointer has reached the end of file.
HandleINTEGERRW
LineCountINTEGERRWXG
LineCount determines how many lines there are in the file. Note that LineCount ignores the CR character, and will only detect LF, so it treats CRLF as one line, but LFLF as 2 lines.
PositionINTEGERRWWXG
Position specifies the current position of the file pointer, any read/write operations will begin from here.
SizeINTEGERRWXG
Size determines the size of the file in bytes.


QFilestream Methods
MethodTypeDescriptionParamsSupport





CloseSUBClose the stream0WXG
CopyFromSUB (Stream, Bytes%)Copy from another stream
Either QFileStream or QMemoryStream
If Bytes%=0 then the whole stream is copied
2W
Use CopyFrom to copy a QFILESTREAM or a QMEMORYSTREAM to the current filestream.
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 File2 AS QFILESTREAM

File1.Open("test.txt", fmCreate)
File2.Open("oldtest.txt", fmOpenRead)
File1.CopyFrom(File2, 123) '-- Copy 123 bytes from File2
ExtractResSUB (Resource AS LONG)Extract resource to filestream1WXG
Extracts a resource from your program to the filestream.
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 File1 AS QFILESTREAM

File1.Open("test.txt", fmCreate)

FOR I = 0 TO ResourceCount-1
    File1.ExtractRes(Resource(I))
NEXT
LoadArraySUB (Array(), NumElements&)Load data into array2WXG
OpenSUB (FileName$, Method%)Open a file, Method% see RAPIDQ.INC2WXG
ReadSUB (variable)Generic Read, determines the storage space and saves data in variable1WXG
Datasize is automatically determined, and the value is stored into the variable.
Example:
$INCLUDE "RAPIDQ.INC"
DIM File1 AS QFILESTREAM
DIM B AS BYTE, I AS INTEGER

File1.Open("test.txt", fmOpenRead)
File1.Read(B) '-- Read a byte
File1.Read(I) '-- Read an integer
ReadLineFUNCTION () AS STRINGReads an entire line, supports UNIX files0WXG
ReadNumFUNCTION (n) AS DOUBLERead n bytes, returns number1WXG
ReadBinStrFUNCTION (n) AS STRINGRead n bytes, returns the binary string1WXG
ReadStrFUNCTION (n) AS STRINGRead n bytes, returns the text string1WXG
ReadUDTSUB (MyType)Read and store data in a MyType structure1WXG
SaveArraySUB (Array(), NumElements&)Save array2WXG
SeekSUB (Position%, From%)Seek to Position%, From% see RAPIDQ.INC2WXG
WriteSUB (variable)Generic Write, determines the storage space and saves data to file1WXG
WriteLineSUB (S AS STRING)Writes string with CR+LF1WXG
WriteNumSUB (number, bytes%)Writes a number to file2WXG
WriteBinStrSUB (string, bytes%)Writes a binary string to file2WXG
WriteStrSUB (string, bytes%)Writes a text string to file (fast)2WXG
WriteUDTSUB (MyType)Write data stored in a MyType structure1WXG


QFileStream Examples
  $INCLUDE "RAPIDQ.INC"

  DIM File AS QFileStream

  File.Open("test.bas", fmOpenRead)
  S$ = File.ReadStr(File.Size)         '' Read entire file
  PRINT S$                             '' print it
  File.Close

'------------------------------------------------------
  $INCLUDE "RAPIDQ.INC"

  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 File AS QFileStream
      File.Open("test", fmCreate)
      File.WriteUDT(Person)


Prev Component Contents Next Component
掌柜推荐
 
 
¥860.00 ·
 
 
¥900.00 ·
 
 
¥810.00 ·
 
 
¥317.00 ·
 
 
¥1,370.00 ·
 
 
¥660.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2015-12-25 19:42:36