Sign in to follow this  
Followers 0
RagsRevenge

File.au3 Unicode functionality

3 posts in this topic

Hello,

I'm writing a program which depends heavily on functions like _fileReadToArray, _fileCreate, etc.

This program is for use in translating between languages, including Unicode languages.

I noticed that a lot of the Open mode parameters of the functions in file.au3 are hardcoded to 0 or 2, ie: not allowing you to pass the Unicode open modes. I was working through file.au3 to create file_ex.au3 which allowed an optional parameter to specify the open mode to these functions.

The read functions seem to work with unicode already, even when an open mode of 0 is used, which is confusing me.

_fileCreate needed to be changed to

Func _FileCreate_Ex($sFilePath, $i_OpenMode = 2)
    ;==============================================
    ; Local Constant/Variable Declaration Section
    ;==============================================
    Local $hOpenFile
    Local $hWriteFile

    $hOpenFile = FileOpen($sFilePath, $i_OpenMode)

    If $hOpenFile = -1 Then
        SetError(1)
        Return 0
    EndIf

    $hWriteFile = FileWrite($hOpenFile, "")

    If $hWriteFile = -1 Then
        SetError(2)
        Return 0
    EndIf

    FileClose($hOpenFile)
    Return 1
EndFunc   ;==>_FileCreate_Ex

to allow me to create Unicode files.

Then I noticed that Jos has remarked

"To use other write modes, like append or Unicode formats, open the file with FileOpen() first and pass the file handle instead.

; If a file handle is passed, the file will still be open after writing." in _FileWriteFromArray.

Am I wasting my time converting these functions to Unicode functions, ie: am I missing something fundamental?

Secondly, is it not better to simply pass the open mode to _FileWriteFromArray, to allow you to append/use unicode? As Jos is a far better coder than I, I expect I'm missing a valid reason to pass the file handle as opposed to the open mode parameter.

Thanks,

D

Share this post


Link to post
Share on other sites



There is no reason why you cannot write to the file using your own code rather than the UDFs? For example writing a file line from an array element is as simple as using a loop and writing the line. Nothing much more than that?

Share this post


Link to post
Share on other sites

There is no reason why you cannot write to the file using your own code rather than the UDFs? For example writing a file line from an array element is as simple as using a loop and writing the line. Nothing much more than that?

I understand this.

I'm used to using the _file.au3 functions, and it's very simple to recode them to make them Unicode compatible.

I guess I'm just curious why the decision was made to hardcode ANSI mode into the functions, and the one reference to Unicode in the UDF, Jos suggests a different process to what I think should be done (pass filehandle as opposed to passing open mode).

In deference to the UDF authors' superior skills, I thought I might have been missing out on very valid reasons not to do what I'm doing, hence the question.

D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0