Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.11.20;
Скачать: CL | DM;

Вниз

Pstream.Save2File   Найти похожие ветки 

 
Lars   (2004-12-30 10:23) [0]

Help if you can...
Easy way to save stream to file?


 
ECM ©   (2004-12-30 12:53) [1]

Memory Stream to File?
...
 
 Stream := NewWriteFileStream(FileName);
 MemStream.Seek(0,spBegin);
 Stream.Write(MemStream.Memory^,MemStream.Size);
 Stream.Free;
...


 
ECM ©   (2004-12-30 12:57) [2]

MemStream.Seek - useless, sorry...


 
miek ©   (2004-12-30 18:20) [3]

Mem2File


 
Lars   (2004-12-30 21:53) [4]

excellent - works just great.


procedure TForm1.Button1Click(Sender: PObj);
var
MemStream1: Pstream;
FileStream1: Pstream;
Filename1: string;
begin
FileName1 := "d:\temp\TestKOLStream.txt"; //file of your choice
MemStream1 := NewMemoryStream;
FileStream1 := NewWriteFileStream(FileName1);
memstream1.WriteStr("Blah Blah Blah!");   //just test it out
//MemStream.Seek(0,spBegin);
FileStream1.Write(MemStream1.Memory^,MemStream1.Size);
FileStream1.Free;
MemStream1.Free;
end;


Miek is Mem2File another in another unit?


 
Lars   (2004-12-30 22:10) [5]

Версия 1.93
[+]KOL: добавлены функции Mem2File и File2Mem.

Ahh I am using 1.91
Time to upgrade Mr. Lars!


 
thaddy   (2005-01-03 18:46) [6]

Here"s what I do to simplify:
// this rewinds one or both streams after use of stream2stream
type
TRewindModes = (rwSource,rwDestination);
TRewindMode = set of TRewindModes;

procedure StreamToStream(dest, Src:PStream;Count:Cardinal;RewindMode:TRewindMode);
begin
 stream2stream(Dest,Src,Count);
 if rwSource in RewindMode then src.seek(0,spbegin);
 if reDestination in RewindMode then dest.seek(0,spBegin);
end;


 
Peter   (2005-03-19 20:05) [7]

PStream.CopyFrom

Please, how can I do it?


 
ECM ©   (2005-03-19 20:43) [8]

Use Stream2StreamXXX function


 
Peter   (2005-03-19 21:33) [9]

Unfortunately, it doesn"t work.

Here is the code so that you see what the problem is :

type
FPosition = record
EndofExe: integer;
end;

// procedure to extract a part of text written at the end of the exe
procedure ExtractPart(myfile:string);
var
 StreamFile, StreamExe: PStream;
 PL: FPosition;
begin
 StreamExe := NewFileStream(ParamStr(0), ofsharedenywrite);
try
StreamExe.Position := StreamExe.size - sizeOf(PL);
StreamExe.Read(PL, sizeOf(PL));
StreamExe.Position := PL.EndOfExe;
StreamFile := NewFileStream(myfile, ofcreatenew);
try
StreamFile.Position := 0;
Stream2Stream(StreamFile,StreamExe, StreamExe.size - sizeOf(PL) - StreamExe.Position);
   finally
StreamFile.FRee;
end;


 
ECM ©   (2005-03-19 22:15) [10]

look like a virus...:)
use the force (F7-"trace into") Luck!


 
Peter   (2005-03-20 09:44) [11]

There is no problem with this code : I used the Antivirus and detect nothing.

The problem is that the file "myfile" is created but has a size of 0 bit !
I don"t know why.

It works good with the function "copyfrom" but not with the function "Stream2Stream" :

StreamFile.CopyFrom(StreamExe, StreamExe.size - sizeOf(PL) - StreamExe.Position);
Stream2Stream(StreamFile,StreamExe, FStreamExe.size - sizeOf(PL) - StreamExe.Position);

Where is the problem please ?


 
Peter   (2005-03-20 09:47) [12]

Excuse me, I did a mistake.

Here is the new code :

It works good with the function "copyfrom" but not with the function "Stream2Stream" :

StreamFile.CopyFrom(StreamExe, StreamExe.size - sizeOf(PL) - StreamExe.Position);
Stream2Stream(StreamFile,StreamExe, StreamExe.size - sizeOf(PL) - StreamExe.Position);

Where is the problem please ?


 
Peter   (2005-03-20 11:11) [13]

Problem resolved.

StreamExe := NewFileStream(ParamStr(0), ofOpenRead or ofOpenExisting or ofsharedenywrite);

instead of

StreamExe := NewFileStream(ParamStr(0), ofsharedenywrite);

Now, it works.


 
Steeve   (2005-03-23 21:05) [14]

Pstream.LoadfromFile

please, method to load a file into a NewMemoryStream

best regards
Steeve


 
thaddy   (2005-03-24 06:43) [15]

var
 MemStr:PStream;
 Filestr:Pstream;
begin
 Memstr:=NewMemorystream;
 try
   FileStr:=NewReadFileStream(YourFilename);
   try
     Stream2Stream(Memstr,FileSTr,Filestr.size);
     Memstr.position:=0;
     // Your code here....!
   finally
     FileStr.free;
   end
     // Or your code here...!
 finally
   memstr.free;
 end;
end.


 
Steeve   (2005-03-26 12:14) [16]

thanks, thaddy !

best regards
Steeve



Страницы: 1 вся ветка

Текущий архив: 2005.11.20;
Скачать: CL | DM;

Наверх




Память: 0.5 MB
Время: 0.05 c
2-1130606810
Del_programmer
2005-10-29 21:26
2005.11.20
canvas


8-1119960584
Grief
2005-06-28 16:09
2005.11.20
Изменение цветов TBitmap;


2-1131090450
dreamse
2005-11-04 10:47
2005.11.20
Как определить есть ли у программы доступ в каталог ?


4-1127071035
Rommel
2005-09-18 23:17
2005.11.20
HOOk dll


2-1131185953
Зм1й
2005-11-05 13:19
2005.11.20
Адекватная реакция :)