[fpc-devel] Method for write string into TStream

2014-07-21 Thread LacaK

Hi,
When I work with f.e. TFileStream I need often write string into stream.
Now I use:
 Stream1.WriteBuffer(s[1], length(s));

I think, that for convenience it will be useful having something like:
procedure TStream.WriteString(const s: string);
 begin
   WriteBuffer(s[1], length(s)*sizeof(char);
 end;

In FPC we now have for user convenience also WriteByte, WriteWord, 
WriteQWord (which all calls WriteBuffer)
and Delphi has lot of overloaded WriteData (but none of them takes as 
parameter string):
 
http://docwiki.embarcadero.com/Libraries/XE3/en/System.Classes.TStream.WriteData


Do you think, that something similar can be added also in FPC ?
Thanks
-Laco.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Syntax choice (was: Blocks support)

2014-07-21 Thread Michael Schnell

On 07/20/2014 10:27 PM, Dmitry Boyarintsev wrote:
 There's no block reserved word in FPC yet (unlike mentioned earlier 
Oxygen).
AFAIU, many keywords are not reserved, but recognized only due to their 
context. Hence somebody could have used block as a normal symbol. But 
in block is compatible with older code and recognizable to the 
compiler due to the reserved word in.


--Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Method for write string into TStream

2014-07-21 Thread Sven Barth
Am 21.07.2014 10:29 schrieb LacaK la...@zoznam.sk:

 Hi,
 When I work with f.e. TFileStream I need often write string into stream.
 Now I use:
  Stream1.WriteBuffer(s[1], length(s));

 I think, that for convenience it will be useful having something like:
 procedure TStream.WriteString(const s: string);
  begin
WriteBuffer(s[1], length(s)*sizeof(char);
  end;

 In FPC we now have for user convenience also WriteByte, WriteWord,
WriteQWord (which all calls WriteBuffer)
 and Delphi has lot of overloaded WriteData (but none of them takes as
parameter string):

http://docwiki.embarcadero.com/Libraries/XE3/en/System.Classes.TStream.WriteData

 Do you think, that something similar can be added also in FPC ?

There is already a WriteAnsiString (
http://www.freepascal.org/docs-html/rtl/classes/tstream.writeansistring.html
) with the difference that it also writes out the length. Adding an
additional overload (especially with a name like WriteString) would IMHO be
confusing because of this.

Nothing stops you though from writing a class helper that adds a
WriteString method to TStream.

Regards,
Sven
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Method for write string into TStreamt

2014-07-21 Thread Marco van de Voort
In our previous episode, Sven Barth said:
  Do you think, that something similar can be added also in FPC ?
 
 There is already a WriteAnsiString (
 http://www.freepascal.org/docs-html/rtl/classes/tstream.writeansistring.html
 ) with the difference that it also writes out the length. Adding an
 additional overload (especially with a name like WriteString) would IMHO be
 confusing because of this.
 
 Nothing stops you though from writing a class helper that adds a
 WriteString method to TStream.

(Except the fact that you can only have one class helper per class?)

Maybe writebinansistring would be a good name. 
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Method for write string into TStream

2014-07-21 Thread Michael Van Canneyt



On Mon, 21 Jul 2014, LacaK wrote:


Sven Barth  wrote / napísal(a):

  Am 21.07.2014 10:29 schrieb LacaK la...@zoznam.sk:
  
   Hi,
   When I work with f.e. TFileStream I need often write string into stream.
   Now I use:
    Stream1.WriteBuffer(s[1], length(s));
  
   I think, that for convenience it will be useful having something like:
   procedure TStream.WriteString(const s: string);
    begin
      WriteBuffer(s[1], length(s)*sizeof(char);
    end;
  
   In FPC we now have for user convenience also WriteByte, WriteWord, 
WriteQWord (which all calls WriteBuffer)
   and Delphi has lot of overloaded WriteData (but none of them takes as 
parameter string):
    
http://docwiki.embarcadero.com/Libraries/XE3/en/System.Classes.TStream.WriteData
  
   Do you think, that something similar can be added also in FPC ?

  There is already a WriteAnsiString ( 
http://www.freepascal.org/docs-html/rtl/classes/tstream.writeansistring.html ) 
with the difference that it also writes out the length.

Yes I know, and I do not want write length only content of string

  Adding an additional overload (especially with a name like WriteString) 
would IMHO be confusing because of this.

Yes without looking into documentation at first look it can by confusable
(what about WriteRawString then) ?

  Nothing stops you though from writing a class helper that adds a 
WriteString method to TStream.

Yes, I can create also own descendant etc. ... but I am asking for general 
solution, which will be useful for all.


Sure:
We can simply add a boolean parameter 'WriteLength : Boolean = True' to the existing call. 
It keeps backwards compatibility, and allows you to write the strings with or without length.


Another option is to add a WriteLn() with various overloaded variants. It 
should be clear then that this will write a textual representation.

Michael.___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Method for write string into TStream

2014-07-21 Thread Marco van de Voort
In our previous episode, Michael Van Canneyt said:
Nothing stops you though from writing a class helper that adds a 
  WriteString method to TStream.
  
  Yes, I can create also own descendant etc. ... but I am asking for general 
  solution, which will be useful for all.
 
 Sure:
 We can simply add a boolean parameter 'WriteLength : Boolean = True' to the 
 existing call. 
 It keeps backwards compatibility, and allows you to write the strings with or 
 without length.

(If so I would make it an enum selecting 0,2,4 bytes length or so)
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Method for write string into TStream

2014-07-21 Thread LacaK

Marco van de Voort  wrote / napísal(a):

In our previous episode, Michael Van Canneyt said:
  

  Nothing stops you though from writing a class helper that adds a 
WriteString method to TStream.

Yes, I can create also own descendant etc. ... but I am asking for general 
solution, which will be useful for all.
  

Sure:
We can simply add a boolean parameter 'WriteLength : Boolean = True' to the existing call. 
It keeps backwards compatibility, and allows you to write the strings with or without length.



(If so I would make it an enum selecting 0,2,4 bytes length or so)
  

Both variants are Ok for me.
But If we will extend WriteAnsiString, then we must IMO also extend 
ReadAnsiString, and in case where length is not a part of streamed data 
then it must be explicitly given as parameter to method call (not only enum)


So IMO simpler will be introduce new methods (like):
 procedure WriteRawString(const s: string);
 function ReadRawString(Len: integer)
or alter existing AnsiString methods to something like:
 type TLengthPrefix = (lenNone, lenWord, lenDWord);
 procedure WriteAnsiString(const s: string; WriteLength: TLengthPrefix 
= lenDWord);
 function ReadAnsiString(ReadLength: TLengthPrefix=lenDWord; Len: 
integer=0);


-Laco.

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Method for write string into TStreamt

2014-07-21 Thread Dmitry Boyarintsev
How about introducing a default parameter?
The parameter keeps the method backward compatible, allowing write a string
without the prefix.

public procedure TStream.WriteAnsiString(
  const S: string;
  withLength: Boolean = true;
);

thanks,
Dmitry


On Mon, Jul 21, 2014 at 5:34 AM, Marco van de Voort mar...@stack.nl wrote:

 In our previous episode, Sven Barth said:
   Do you think, that something similar can be added also in FPC ?
 
  There is already a WriteAnsiString (
 
 http://www.freepascal.org/docs-html/rtl/classes/tstream.writeansistring.html
  ) with the difference that it also writes out the length. Adding an
  additional overload (especially with a name like WriteString) would IMHO
 be
  confusing because of this.
 
  Nothing stops you though from writing a class helper that adds a
  WriteString method to TStream.

 (Except the fact that you can only have one class helper per class?)

 Maybe writebinansistring would be a good name.
 ___
 fpc-devel maillist  -  fpc-devel@lists.freepascal.org
 http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Method for write string into TStreamt

2014-07-21 Thread Sven Barth
Am 21.07.2014 11:34 schrieb Marco van de Voort mar...@stack.nl:

 In our previous episode, Sven Barth said:
   Do you think, that something similar can be added also in FPC ?
 
  There is already a WriteAnsiString (
 
http://www.freepascal.org/docs-html/rtl/classes/tstream.writeansistring.html
  ) with the difference that it also writes out the length. Adding an
  additional overload (especially with a name like WriteString) would
IMHO be
  confusing because of this.
 
  Nothing stops you though from writing a class helper that adds a
  WriteString method to TStream.

 (Except the fact that you can only have one class helper per class?)

Doesn't stop him from writing the helper, only from using it :P

Regards,
Sven
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Syntax choice (was: Blocks support)

2014-07-21 Thread Dmitry Boyarintsev
On Sun, Jul 20, 2014 at 6:28 PM, Jonas Maebe jonas.ma...@elis.ugent.be
wrote:


 I proposed to use is block because of the analogy with the already
 existing is nested. Neither block nor nested was/is/would be a
 reserved word afterwards, just like many other words that have a special
 meaning in one context or another (look at compiler/tokens.pas; most tokens
 are not reserved words.


Yes, true. I should have not used reserved term but rather context
special words.
And since is nested is there, it does make sense to propose is block.


 It's also a similar concept (you have a pointer to something that
 describes a function), but it's incompatible and different so you need a
 different syntax. Any different syntax is fine, as far as I'm concerned.


It's just my personal appeal to reuse as many of existing reserved/context
words as possible. (In which case is block seems better to me, than
reference to... just because its less typing, though too block-specific)

I'd think that as soon as the feature is added to the trunk, some other
source parsing libraries (CodeTools, fpc-passrc) needs to be updated.

thanks,
Dmitry
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Syntax choice (was: Blocks support)

2014-07-21 Thread Sven Barth
Am 21.07.2014 18:15 schrieb Dmitry Boyarintsev skalogryz.li...@gmail.com
:

 On Sun, Jul 20, 2014 at 6:28 PM, Jonas Maebe jonas.ma...@elis.ugent.be
wrote:

 It's also a similar concept (you have a pointer to something that
describes a function), but it's incompatible and different so you need a
different syntax. Any different syntax is fine, as far as I'm concerned.


 It's just my personal appeal to reuse as many of existing
reserved/context words as possible. (In which case is block seems better
to me, than reference to... just because its less typing, though too
block-specific)

The point is that we'll need the reference to anyway for Delphi
compatibility. Otherwise I agree that Pascal normally uses suffixes...

Regards,
Sven
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


Re: [fpc-devel] Method for write string into TStreamt

2014-07-21 Thread Hans-Peter Diettrich

Dmitry Boyarintsev schrieb:

How about introducing a default parameter?
The parameter keeps the method backward compatible, allowing write a 
string without the prefix.


public procedure TStream.WriteAnsiString(
  const S: string;
  withLength: Boolean = true;


How should a string without a length be read back?

DoDi

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel