Page 2 of 2
Insert text at top of a file
Posted: Mon Dec 31, 2018 1:14 pm
by robert
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
Posted: Mon Dec 31, 2018 1:53 pm
by Karl-Heinz
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
Insert text at top of a file
Posted: Mon Dec 31, 2018 4:24 pm
by Jamal
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
Insert text at top of a file
Posted: Tue Jan 01, 2019 9:21 pm
by Chris
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
Insert text at top of a file
Posted: Tue Jan 01, 2019 10:25 pm
by FFF
Chris wrote:... or is it better to adjust such code so that it uses directly the appropriate .Net method for reading binary data?
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 brain
my .1
Karl
Insert text at top of a file
Posted: Wed Jan 02, 2019 12:42 pm
by robert
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