was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

49 Visitors Online


 
...TMemoryStream verwenden um Daten zu speichern?
Autor: Damian Gorski
[ Tip ausdrucken ]  

Tip Bewertung (10):  
     


{Think of memory stream as a file that is located in memory.  So the writes
are very similar to the write command for files.  (Actually it is closer to
the blockwrite command.)}

{To put a string the slow way you could do the following:}

    
for i := 1 to Length(s) do memstream.Write(s[i], 1);

{That would write the string one character at a time.  Simple and easy to
understand, but a bit slow.  A faster way would be to do the following:}

    
memstream.Write(s[1], Length(s));

{The two lines do the same thing, they append characters to the stream. If
you have never done a seek on the stream, they just append to the end.}

{Now to handle the line feeds you have to add them yourself:}

    
memstream.Write(#13, 1);
    memstream.Write(#10, 1);

{Or you could do some sneaky things like this:}

    
procedure StreamWriteStr(var ms: TMemoryStream; s: string);
    begin
        
ms.Write(s[1], Length(s));
    end;

    procedure StreamWriteLnStr(var ms: TMemoryStream; s: string);
    begin
        
StreamWriteStr(ms, s + #13#10);
    end;

{Or you could create you own descendant class of TMemoryStream with a method
to write strings.}

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


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