Karl-Heinz,
This is not possible and not wanted. People expect to be able to read an Ansi text file and see the contents as Unicode text in their app.
We can't support that and read/write binary files at the same time.
To do this in .Net you need to use System.IO.File.ReadAllBytes().
We could add a MemoReadBinary() and MemoWriteBinary() for that purpose, but that would just be a wrapper around ReadAllBytes() and WriteAllBytes().
Do you think this is needed ?
Robert
Note: of course these functions would not return or accept a string. Most likely a byte[].
Insert text at top of a file
Insert text at top of a file
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
-
- Posts: 774
- Joined: Wed May 17, 2017 8:50 am
- Location: Germany
Insert text at top of a file
Hi Robert,
as i wrote, i never used MemoRead()/MemoWrit() this way before. But searching the intl VO google group shows that sometimes memoread() is used to read bitmaps from disk and show them in a FabControl ?
Personally i don´t expect and don´t need this VO behaviour, but finally it's your decision what to do. At least, it would be nice if WriteAllText() and .ReadAllText() would respect the SetAnsi() setting as i mentioned some msgs above.
regards
Karl-Heinz
as i wrote, i never used MemoRead()/MemoWrit() this way before. But searching the intl VO google group shows that sometimes memoread() is used to read bitmaps from disk and show them in a FabControl ?
Personally i don´t expect and don´t need this VO behaviour, but finally it's your decision what to do. At least, it would be nice if WriteAllText() and .ReadAllText() would respect the SetAnsi() setting as i mentioned some msgs above.
regards
Karl-Heinz
Insert text at top of a file
Robert,
I was referring to VO's MemoRead not X#.
However, as to Karl's issue, I would suggest may be you can overload the MemoRead function in X#, i.e. (I assume this possible in X#, as I have not read the docs and dived deep into it).
MemoRead(cFile)
MemoRead(cFile, lSetAnsi)
MemoRead(cFile, lSetAnsi, uEncoding)
Jamal
However
I was referring to VO's MemoRead not X#.
However, as to Karl's issue, I would suggest may be you can overload the MemoRead function in X#, i.e. (I assume this possible in X#, as I have not read the docs and dived deep into it).
MemoRead(cFile)
MemoRead(cFile, lSetAnsi)
MemoRead(cFile, lSetAnsi, uEncoding)
Jamal
However
Insert text at top of a file
Guys,
I agree, MemoRead() and MemoWrite() need to be adjusted as Karl-Heinz suggested, so that they can properly read ansi and oem text files depending on the SetAnsi() function, for compatibility with VO.
But for reading/writing binary data, only way to do it is by using more overloads as Jamal said, or provide different functions like MemoReadBinary() that Robert pointed out. using overloads has the disadvantage that one overload of MemoRead() needs to return a string and others need to return a byte array, so it can be confusing.
But, in any case, all that MemoRead() basically does is to call System.IO.File.ReadAllText(). So is it really worth it providing more overloads or more functions for that simple thing, or is it better to adjust such code so that it uses directly the appropriate .Net method for reading binary data? Anyway such code will need to be adjusted so that it uses a byte array as an intermediate buffer instead of a string, so I think it is more practical to also use directly the proper method (File.ReadAllBytes() for example).
Chris
I agree, MemoRead() and MemoWrite() need to be adjusted as Karl-Heinz suggested, so that they can properly read ansi and oem text files depending on the SetAnsi() function, for compatibility with VO.
But for reading/writing binary data, only way to do it is by using more overloads as Jamal said, or provide different functions like MemoReadBinary() that Robert pointed out. using overloads has the disadvantage that one overload of MemoRead() needs to return a string and others need to return a byte array, so it can be confusing.
But, in any case, all that MemoRead() basically does is to call System.IO.File.ReadAllText(). So is it really worth it providing more overloads or more functions for that simple thing, or is it better to adjust such code so that it uses directly the appropriate .Net method for reading binary data? Anyway such code will need to be adjusted so that it uses a byte array as an intermediate buffer instead of a string, so I think it is more practical to also use directly the proper method (File.ReadAllBytes() for example).
Chris
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
Insert text at top of a file
If we have a problem with .Net, it's the overwhelming mass of funcs - so, for this case, don't put another load on our brainChris wrote:... or is it better to adjust such code so that it uses directly the appropriate .Net method for reading binary data?
my .1
Karl
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Insert text at top of a file
Karl,
I have made the following changes:
1) Inside in MemoRead() and MemoWrit() the necessary conversion from 8 bit ansi or 8bit oem to unicode are done
2) I have added new functions MemoReadBinary() and MemoWritBinary() to work with the contents of binary files. The content is represented as an array of bytes (byte[]).
Robert
I have made the following changes:
1) Inside in MemoRead() and MemoWrit() the necessary conversion from 8 bit ansi or 8bit oem to unicode are done
2) I have added new functions MemoReadBinary() and MemoWritBinary() to work with the contents of binary files. The content is represented as an array of bytes (byte[]).
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu