XProfan Forum Community: Nach Serverausfall, noch geht fast nix, bin dran!

English
Units

FileClass - ex XProfan 8 Unit as class incl. Source

 
The first Version of my FileClass-Unit is ready

Please not the File-Unit confuse

yet is the selection on classes for XProfan Yes another slightly dürftig, therefore (and naturally from personal interest) Have I decided a FileClass to create. These class can almost as much as you want Files at the same time create, Edit or reading (independent of whom Profan-internen command).
any modes (functions in the class) beruhen on reinem windows-API. an direct distinction of binary- and Text files there not. The Syntax is too very simply.
in the beiligendem Source any modes in detail described, furthermore have I 3 Examples enclosed, The a Entry relieve should.
The Unit should, I hope indeed on a morsel of Teamwork, yet moreover expanded go. Einschränkungen to Time: Fehlerbehandlung yet Stiefmütterlich
speed with Zeilenweise reading of Texten not yet so particularly (yet is yet no Pufferung installed).

Dateisystemfunktionen, means create of Folders, detect of Pfaden etc. are not planned. The class should solely Dateioperationen perform. self-evident can later too self-contained a FileSystemClass create, The with want of this class erbt

Greeting
Thomas
(ts-soft)
 $L
 $H windows.ph

{

    Class ?_File = -hFile&,
    -FileError&,
    +Error@,
    +Close@,
    +Create@,
    +Eof@,
    +Seek@,
    +Loc@,
    +Lof@,
    +Open@,
    +Read@,
    +GetFile@,
    +GetByte@,
    +GetWord@,
    +GetLong@,
    +GetFloat@,
    +GetString@,
    +GetData@,
    +PutByte@,
    +PutWord@,
    +PutLong@,
    +PutFloat@,
    +PutString@,
    +PutStringCR@,
    +PutData@,
    +Version@

}

################################################
# create, öffnen and close of Files #
################################################
Syntax: OBJEKT#.Create(FileName$)
Result: lever the Files,
in the Fehlerfall -1, OBJEKT#.Error becomes on TRUE staid
Statement: Öffnet a vain File. existing The angegebene File already,
becomes these opened and through a vain supplant!!!

Proc ?_File.Create

    Parameters FileName$
    .FileError& = 0

    {

        .hFile& = ~CreateFile(Addr(FileName$),
        OR(~GENERIC_WRITE,~GENERIC_READ),
        0,
        0,
        ~CREATE_ALWAYS,
        ~FILE_ATTRIBUTE_NORMAL,
        0)

    }

    Case .hFile& = ~INVALID_HANDLE_VALUE : .FileError& = 1
    Return .hFile&

ENDPROC

Syntax: OBJEKT#.Open(FileName$)
Result: lever the Files,
in the Fehlerfall -1, OBJEKT#.Error becomes on TRUE staid
Statement: Öffnet The angegebene File or prepares a,
if yet no existing. You can now read- and Schreibfunktionen in this File perform

Proc ?_File.Open

    Parameters FileName$
    .FileError& = 0

    {

        .hFile& = ~CreateFile(Addr(FileName$),
        OR(~GENERIC_WRITE, ~GENERIC_READ),
        ~FILE_SHARE_READ | ~FILE_SHARE_WRITE,
        0,
        ~OPEN_ALWAYS,
        ~FILE_ATTRIBUTE_NORMAL,
        0)

    }

    Case .hFile& = ~INVALID_HANDLE_VALUE : .FileError& = 1
    Return .hFile&

ENDPROC

Syntax: OBJEKT#.Read(FileName$)
Result: lever the Files,
in the Fehlerfall -1, OBJEKT#.Error becomes on TRUE staid
Statement: Öffnet a existing File FileName$ solely for read-Operationen

Proc ?_File.Read

    Parameters FileName$
    .FileError& = 0

    {

        .hFile& = ~CreateFile(Addr(FileName$),
        ~GENERIC_READ,
        ~FILE_SHARE_READ,
        0,
        ~OPEN_EXISTING,
        ~FILE_ATTRIBUTE_NORMAL,
        0)

    }

    Case .hFile& = ~INVALID_HANDLE_VALUE : .FileError& = 1
    Return .hFile&

ENDPROC

Syntax: OBJEKT#.Close([File&])
Result: keins
Statement: closes The actually File, which so not moreover using go can
If the optionale Parameter File& übergeben becomes, becomes these File closed, The
actually File remaining hiervon unbeeinflusst

Proc ?_File.Close

    If %PCount = 1

        Parameters file&
        ~CloseHandle(file&)

    Else

        ~CloseHandle(.hFile&)
        .hFile& = 0

    EndIf

ENDPROC

###############
# data reading #
###############
Syntax: OBJEKT#.GetByte()
Result: gelesenes byte
Statement: reads one byte from the currently opened File one

Proc ?_File.GetByte

    Declare temp1&, temp2#
    Dim temp2#, 1
    ~ReadFile(.hFile&, Addr(temp1&), 1, Addr(temp2#), 0)
    Dispose temp2#
    Return temp1&

ENDPROC

Syntax: OBJEKT#.GetWord()
Result: gelesenes Word
Statement: reads one Word from the currently opened File one

Proc ?_File.GetWord

    Declare temp1&, temp2#
    Dim temp2#, 2
    ~ReadFile(.hFile&, Addr(temp1&), 2, Addr(temp2#), 0)
    Dispose temp2#
    Return temp1&

ENDPROC

Syntax: OBJEKT#.GetLong()
Result: gelesenes Long&
Statement: reads one Long from the currently opened File one

Proc ?_File.GetLong

    Declare temp1&, temp2&
    ~ReadFile(.hFile&, Addr(temp1&), 4, Addr(temp2&), 0)
    Return temp1&

ENDPROC

Syntax: OBJEKT#.GetFloat()
Result: gelesenes Float!
Statement: reads one Float from the currently opened File one

Proc ?_File.GetFloat

    Declare temp1!, temp2#
    Dim temp2#, 8
    ~ReadFile(.hFile&, Addr(temp1!), 8, Addr(temp2#), 0)
    Dispose temp2#
    Return temp1!

ENDPROC

Syntax: OBJEKT#.GetString()
Result: gelesene TextZeile as Text$
Statement: reads a String from the currently opened File,
To one End Of Line characters found is. UNIX or DOS

Proc ?_File.GetString

    Declare buffer#, bytesread&, Text$
    Dim buffer#, 1

    While ~SetFilePointer(.hfile&, 0, 0, ~FILE_CURRENT) < ~GetFileSize(.hfile&, 0)

        ~ReadFile(.hfile&, Addr(buffer#), 1, Addr(bytesread&), 0)
        Case byte(buffer#,0) = 0 : break
        Case byte(buffer#,0) = 10 : break
        Text$ = Text$ + Chr$(byte(buffer#,0))

    EndWhile

    Dispose buffer#
    Return Translate$(Text$, Chr$(13), "")

ENDPROC

Syntax: OBJEKT#.GetData(MemoryBuffer&, LengthToRead&)
Result: keins (gelesene Bytes find itself in the MemoryBuffer&)
Description: reads whom Content the actually File with the
angegebenen length LengthToRead& (amount To einzulesender characters)
in whom angegebenen Speicherbereich MemoryBuffer& in example address
of/ one Memory-Variable

Proc ?_File.GetData

    Parameters MemoryBuffer&, LengthToRead&
    Declare buffer#
    Dim buffer#, LengthToRead&
    ~ReadFile(.hFile&, MemoryBuffer&, LengthToRead&, Addr(buffer#), 0)
    Dispose buffer#

ENDPROC

###################
# data write #
###################
The here subesquent modes functions only,
if The File with Schreib-Support opened watts
(either with Create or Open)
Syntax: OBJEKT#.PutByte(Wert&)
Result: keins
Statement: writes a byte-worth in The actually File.

Proc ?_File.PutByte

    Parameters Number&
    Declare Temp#
    Dim Temp#, 1
    ~WriteFile(.hFile&, Addr(Number&), 1, Temp#, 0)
    Dispose Temp#

ENDPROC

Syntax: OBJEKT#.PutWord(Wert&)
Result: keins
Statement: writes a Word-worth in The actually File.

Proc ?_File.PutWord

    Parameters Number&
    Declare Temp#
    Dim Temp#, 2
    ~WriteFile(.hFile&, Addr(Number&), 2, Temp#, 0)
    Dispose Temp#

ENDPROC

Syntax: OBJEKT#.PutLong(Wert&)
Result: keins
Statement: writes a Long-worth in The actually File.

Proc ?_File.PutLong

    Parameters Number&
    Declare Temp&
    ~WriteFile(.hFile&, Addr(Number&), 4, Addr(Temp&), 0)

ENDPROC

Syntax: OBJEKT#.PutFloat(worth!)
Result: keins
Statement: writes a Float-worth in The actually File.

Proc ?_File.PutFloat

    Parameters Number!
    Declare Temp!
    ~WriteFile(.hFile&, Addr(Number!), 8, Addr(Temp!), 0)

ENDPROC

Syntax: OBJEKT#.PutString(Text$)
Result: keins
Statement: writes a String in The actually File

Proc ?_File.PutString

    Parameters Text$
    Declare Temp#
    Dim Temp#, Len(Text$)
    ~WriteFile(.hFile&, Addr(Text$), Len(Text$), Addr(Temp#), 0)
    Dispose Temp#

ENDPROC

Syntax: OBJEKT#.PutStringCR(Text$)
Result: keins
Statement: writes a String in The actually File
and fügt one EOL Line break hinzu

Proc ?_File.PutStringCR

    Parameters Text$
    Declare Temp#
    Text$ = Text$ + Chr$(13) + Chr$(10)
    Dim Temp#, Len(Text$)
    ~WriteFile(.hFile&, Addr(Text$), Len(Text$), Addr(Temp#), 0)
    Dispose Temp#

ENDPROC

Syntax: OBJEKT#.PutData(MemoryBuffer&, LengthToWrite&)
Result: keins
Statement: writes whom Content the angegebenen Speicherbereichs
MemoryBuffer& with of/ one length of LengthToWrite& in The actually File.

Proc ?_File.PutData

    Parameters MemoryBuffer&, LengthToWrite&
    Declare buffer#
    Dim buffer#, LengthToWrite&
    ~WriteFile(.hFile&, MemoryBuffer&, LengthToWrite&, Addr(buffer#), 0)
    Dispose buffer#

ENDPROC

############
# Diverses #
############
Syntax: OBJEKT#.Error()
Result: 0 or 1
Statement: gives in the Fehlerfall True (1) back
Z. Zt. becomes only on ~INVALID_HANDLE_VALUE with
OBJEKT#.Create(), OBJEKT#.Open() and OBJEKT#.Read() examined

Proc ?_File.Error

    Return .FileError&

ENDPROC

Syntax: OBJEKT#.GetFile()
Result: lever the Files
Statement: herewith can too as an afterthought the
lever the actually File determined go

Proc ?_File.GetFile

    Return .hFile&

ENDPROC

Syntax: OBJEKT#.Eof()
Result: 0 or 1
Statement: herewith detect we whether the end the
File access watts (1) or not (0)

Proc ?_File.Eof

    Declare Result&

    If ~SetFilePointer(.hFile&, 0, 0, ~FILE_CURRENT) < ~GetFileSize(.hFile&, 0)

        Result& = 0

    Else

        Result& = 1

    EndIf

    Return Result&

ENDPROC

Syntax: OBJEKT#.Loc()
Result: position
Statement: gives The actually Zeiger-position
within the File back

Proc ?_File.Loc

    Return ~SetFilePointer(.hFile&, 0, 0, ~FILE_CURRENT)

ENDPROC

Syntax: OBJEKT#.Seek(NewPosition&)
Result:
Description: Ändert whom read/Schreib - Zeiger within
the File on The angegebene NeuePosition. this
Parameter must in Bytes indicated go

Proc ?_File.Seek

    Parameters NewPosition&
    Return ~SetFilePointer(.hFile&, NewPosition&, 0, ~FILE_BEGIN)

ENDPROC

Syntax: OBJEKT#.Lof()
Result: FileSize
Statement: LOF standing for Length Of File (length the File).
it gives The length the actually File back

Proc ?_File.Lof

    Return ~GetFileSize(.hFile&, 0)

ENDPROC

Syntax: OBJEKT#.Version()
Result: Version
Statement: gives The actually Version
this class as String again

Proc ?_File.Version

    Return "0.5.5.18"  master-Version.year.month.day

ENDPROC


10 kB
Hochgeladen:05/18/05
Downloadcounter188
Download
 
05/13/05  
 



Have The Unit time updated.

OBJEKT#.UseFile(hFile&) watts removes. made unfortunately partly Problems. circa several Files benefit, is it now necessary for each File a new instance the class anzulegen. increased of course something whom Schreibaufwand, but its nevertheless furthermore possible almost as much as you want Files at the same time To Edit.
the example Test3.prf watts hereon angepaßt and same yet fehlerbereinigt.
with the vorigen Version, are me on my system no Error noticed, solely Rolf shared me these with. Habs indeed hopefully now eliminating. i'm means the testing of you dependent.

Greeting
Thomas
 
05/18/05  
 



Habs short tested and working well.

by me means Fehlerfrei.

circa not The Number of Downloads each time with one Update on 0 To settle - use still first whom search button - and then click on new version.

salvo.
 
05/18/05  
 



Hello Thomas...

be unfortunately (yet) no XProfan User, therefore I will first time neither testing.
related on ~Generic_write | ~Generic_read could you but since one Profanbug evtl. time something Problems bound. look time in Bugnity to...
 
05/18/05  
 



[quote:1382f2518b=iF]Habs short tested and working well.

by me means Fehlerfrei.[/quote:1382f2518b]the Freud me first
[quote:1382f2518b=iF]
circa not The Number of Downloads each time with one Update on 0 To settle - use still first whom search button - and then click on new version.

salvo.[/quote:1382f2518b]
Habs well again wrong made

[quote:1382f2518b=AH]look time in Bugnity to...
[/quote:1382f2518b]Have The suitable to put with OR angepaßt

Greeting
Thomas
 
05/18/05  
 




Rolf
Koch
Hi Thomas,

Yes It's all right now!

Rolf
 
05/18/05  
 



[quote:5439b97a2c]again wrong made[/quote:5439b97a2c]go still simply time into arena - there can be testing so plenty one would like.

salvo.
 
05/18/05  
 




Michael
Wodrich
Nachfolgend a function with Blockpuffer.
Proc ?_file.getstring

    Declare Buffer#, Bytesread&, Text$, Text2$, FSize&, aktPos&, found&
    Dim Buffer#, 1024
    FSize& = ~Getfilesize(.Hfile&, 0)
    aktPos& = ~Setfilepointer(.Hfile&, 0, 0, ~File_current)

    While aktPos& < FSize&

        ~Readfile(.Hfile&, Addr(Buffer#), 1024, Addr(Bytesread&), 0)
        Found& = MemPos(Buffer#,0,Chr$(0))

        If Found& <> -1

            Text2$ = String $(Buffer#,0)
            Text$ = Text$ + Text2$
            aktPos& = aktPos& + Len(Text2$) + 1
            ~Setfilepointer(.Hfile&, aktPos&, 0, ~File_Begin)
            Break

        EndIf

        Found& = MemPos(Buffer#,0,Chr$(10))

        If Found& <> -1

            Text2$ = Char$(Buffer#,0,Found&)
            Text$ = Text$ + Text2$
            aktPos& = aktPos& + Len(Text2$) + 1
            ~Setfilepointer(.Hfile&, aktPos&, 0, ~File_Begin)
            Break

        EndIf

        aktPos& = ~Setfilepointer(.Hfile&, 0, 0, ~File_current)

    Endwhile

    Dispose Buffer#
    Return Translate$(Text$, Chr$(13), "")

Endproc

 
Programmieren, das spannendste Detektivspiel der Welt.
12/23/05  
 



Beautiful, which is still one for this Unit-interested
Perhaps ought to one whom Buffer on 4096 raise, only from the Grunde, because the worth in others me known functions too taken becomes. i think time is no chance his.

glad Weihnacht
 
12/23/05  
 



Answer


Topictitle, max. 100 characters.
 

Systemprofile:

no Systemprofil laid out. [anlegen]

XProfan:

 Posting  Font  Smilies  ▼ 

Please register circa a Posting To verfassen.
 

Topic-Options

7.536 Views

Untitledvor 0 min.
Gast.081508/19/24
Member 862464104/20/24
Paul Glatz09/16/18
Georg Teles01/16/16
More...

Themeninformationen



Admins  |  AGB  |  Applications  |  Authors  |  Chat  |  Privacy Policy  |  Download  |  Entrance  |  Help  |  Merchantportal  |  Imprint  |  Mart  |  Interfaces  |  SDK  |  Services  |  Games  |  Search  |  Support

One proposition all XProfan, The there's!


My XProfan
Private Messages
Own Storage Forum
Topics-Remember-List
Own Posts
Own Topics
Clipboard
Log off
 Deutsch English Français Español Italia
Translations

Privacy Policy


we use Cookies only as Session-Cookies because of the technical necessity and with us there no Cookies of Drittanbietern.

If you here on our Website click or navigate, stimmst You ours registration of Information in our Cookies on XProfan.Net To.

further Information To our Cookies and moreover, How You The control above keep, find You in ours nachfolgenden Datenschutzerklärung.


all rightDatenschutzerklärung
i want none Cookie