New_RFile | |||
Syntax: | |||
New_RFile() | |||
Return Values: | |||
| |||
Description: | |||
Create a new RFile-Object | |||
Example: | |||
; Interface for RFile-Object, declared in PBOSL.res! Interface IRFile Create(FileName.s, RecordLength.l) ; Create and open FileName with RecordLength Open(FileName.s) ; Open existing RFile Close() ; Close RFile and destroy object RecCount() ; Count of record, zero based! Eof() ; End of RFile, last record Lof() ; Filesize of RFile RecordLength() ; Length of records MaxRecord() ; Max records (max. filesize: 2 GB) LastUpdate() ; Date of last modification in PB-Date-Format CreationDate() ; Date of creation RFile in PB-Date-Format Version() ; LibVersion: 2.0 = HighByte 2, LowByte 0 (512) VersionStr.s() ; LibVersion as string: RFile-Version: 2.0 Put(RecordNumber.l, MemoryPointer.l) ; Save data from mem to RecordNumber, for RecordNumber see Remarks Get(RecordNumber.l, MemoryPointer.l) ; Load data RecordNumber to mem Append(MemoryPointer.l) ; Append a record Crypt(MemoryPointer.l, PassWord.s) ; En- or Decrypt record EndInterface ; Exmple 1 ; write data Structure URLS Name.b[40] URL.b[50] EndStructure Global File.IRFile Procedure Append(Name.s, URL.s) Adr.URLS PokeS(@Adr\Name[0], Left(Name, 40)) PokeS(@Adr\URL[0], Left(URL, 50)) File\Append(@Adr) EndProcedure ; create Object File.IRFile = New_RFile() If File If File\Open("adress.dat") = #False; if you run the example again, it's added 2 records File\Create("adress.dat", SizeOf(URLS)); new randomfile EndIf Append("TS-Soft", "http://purebasic.ts-soft-online.de") Append("PureBasic", "http://www.purebasic.com") MessageRequester(File\VersionStr(), "adress.dat with: " + Str(File\RecCount() + 1) + " records created", #MB_ICONINFORMATION) File\Close() Else MessageRequester("ERROR", "can't create RFile-Object", #MB_ICONERROR) EndIf ;Example 2 ; read data ; Structur of data in RFile Structure URLS Name.b[40] URL.b[50] EndStructure Adr.URLS ; create Object File.IRFile = New_RFile() If File If File\Open("adress.dat") Repeat File\Get(#RFile_Next, @Adr); read next record in structured Variable Text$ + PeekS(@Adr\Name[0]) + Chr(10) Text$ + PeekS(@Adr\URL[0]) + Chr(10) + Chr(10) Until File\Eof() Text$ + "Recordcount: " + Str(File\RecCount() + 1) + Chr(10) Text$ + "last modification: " + FormatDate("%yyyy/%mm/%dd", File\LastUpdate()) MessageRequester(File\VersionStr(), Text$, #MB_ICONINFORMATION) Else MessageRequester("ERROR", "can't open adress.dat", #MB_ICONERROR) EndIf File\Close() Else MessageRequester("ERROR", "can't create RFile-Object", #MB_ICONERROR) EndIf | |||
Remarks: | |||
for RecordNumber you can use this constants: #RFile_First #RFile_Previous #RFile_Next #RFile_Last #RFile_Current | |||
|