Top.Mail.Ru
Мастера DELPHI, Delphi programming community Титульная страница Поиск, карта сайта Написать письмо 
| Новости | Поиск | FAQ | Статьи | Книги | Новости VCL |
| Форумы ЧАТ | Орешник | KOL и MCK |
Форумы -» Основная («Начинающим»)/ Базы / WinAPI / Компоненты / Сети / Media / Игры / Corba и COM / KOL / FreePascal / .Net / Прочее / RSDN.ORG

« предыдущая ветвь | форум | следующая ветвь »

Pstream.Save2File


Lars ©   (2004-12-30 10:23:00) 

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


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

thanks, thaddy !

best regards
Steeve


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

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-23 21:05:00) [3]

Pstream.LoadfromFile

please, method to load a file into a NewMemoryStream

best regards
Steeve


Peter   (2005-03-20 11:11:00) [4]

Problem resolved.

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

instead of

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

Now, it works.


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

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 09:44:00) [6]

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 ?


ECM   (2005-03-19 22:15:00) [7]

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


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

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 20:43:00) [9]

Use Stream2StreamXXX function


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

PStream.CopyFrom

Please, how can I do it?


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

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;


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

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

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


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

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?


miek   (2004-12-30 18:20:00) [14]

Mem2File


ECM   (2004-12-30 12:57:00) [15]

MemStream.Seek - useless, sorry...


ECM   (2004-12-30 12:53:00) [16]

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


Наверх

Титульная страница Поиск, карта сайта Написать письмо