Insert text at top of a file

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Insert text at top of a file

Post 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[].
XSharp Development Team
The Netherlands
robert@xsharp.eu
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

Insert text at top of a file

Post 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
Jamal
Posts: 315
Joined: Mon Jul 03, 2017 7:02 pm

Insert text at top of a file

Post 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
User avatar
Chris
Posts: 4910
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Insert text at top of a file

Post 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
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Insert text at top of a file

Post 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
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Insert text at top of a file

Post 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
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply