whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

42 Visitors Online


 
...use some TStream utility functions?
Autor: Thomas Mueller
Homepage: http://www.s2h.cx
[ Print tip ]  

Tip Rating (5):  
     


{
 These are three utility functions to write strings to a TStream.
 Nothing fancy, but I just ended up coding this repeatedly so
 I made these functions. }

{
 Hier sind einige TStreaam Hilfsfunktionen um strings
 in einen TStream zu schreiben.
}


unit ClassUtils;

interface

uses
  
SysUtils,
  Classes;

{: Write a string to the stream
   @param Stream is the TStream to write to.
   @param s is the string to write
   @returns the number of bytes written. }
function Writestring(_Stream: TStream; const _s: string): Integer;

{: Write a string to the stream appending CRLF
   @param Stream is the TStream to write to.
   @param s is the string to write
   @returns the number of bytes written. }
function WritestringLn(_Stream: TStream; const _s: string): Integer;

{: Write formatted data to the stream appending CRLF
   @param Stream is the TStream to write to.
   @param Format is a format string as used in sysutils.format
   @param Args is an array of const as used in sysutils.format
   @returns the number of bytes written. }
function WriteFmtLn(_Stream: TStream; const _Format: string;
  _Args: array of const): Integer;

implementation

function 
Writestring(_Stream: TStream; const _s: string): Integer;
begin
  
Result := _Stream.Write(PChar(_s)^, Length(_s));
end;

function WritestringLn(_Stream: TStream; const _s: string): Integer;
begin
  
Result := Writestring(_Stream, _s);
  Result := Result + Writestring(_Stream, #13#10);
end;

function WriteFmtLn(_Stream: TStream; const _Format: string;
  _Args: array of const): Integer;
begin
  
Result := WritestringLn(_Stream, Format(_Format, _Args));
end;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners