Hi,
I have a small problem copying part of a MemoryStream (Stream) into another MemoryStream (FoundStr).
I have a long RTF document that I load into a memory stream and then search for different sections based of a bunch of changing requirements. I then want to load the new MemoryStream into the RichEdit Box (Description_RE).
I have the start position already found :- StartPos: Int64;
I have string from the end of the section I am interested in (s) - happens to be '====================================='
The new stream is "FoundStr"
The source stream "Stream" is currently a global veriable.
The line
FoundStr.CopyFrom(Stream, (EndPos - StartPos));
does not work.
I have the correct position as I have put in the line
Stream.Read(Buffer1[0],250);
in its place and the contents of Buffer1 is correct.
Any ideas what I am doing wrong?
procedure TForm1.GetDescription(StartPos: Int64; S: String);
var
Buffer1, Buffer2: array[0..254] of Char;
FoundStr : TMemoryStream;
EndPos : Int64;
begin
Description_RE.Clear;
FillChar(Buffer1, 255, #0);
FillChar(Buffer2, 255, #0);
StrPCopy(@Buffer2, S);
FoundStr := TMemoryStream.Create;
Stream.Position := StartPos;
Stream.Read(Buffer1[0],Length(S));
while (not CompareMem(@Buffer1,@Buffer2,Length(S))) do
begin
if Stream.Position = Stream.Size then exit;
Stream.Position := Stream.Position - (Length(S) - 1);
Stream.Read(Buffer1[0], Length(S));
end;
EndPos := Stream.Position - Length(S);
Stream.Position := StartPos;
FoundStr.CopyFrom(Stream, (EndPos - StartPos));
Description_RE.Lines.LoadFromStream(FoundStr);
FoundStr.Free;
end;
I have a small problem copying part of a MemoryStream (Stream) into another MemoryStream (FoundStr).
I have a long RTF document that I load into a memory stream and then search for different sections based of a bunch of changing requirements. I then want to load the new MemoryStream into the RichEdit Box (Description_RE).
I have the start position already found :- StartPos: Int64;
I have string from the end of the section I am interested in (s) - happens to be '====================================='
The new stream is "FoundStr"
The source stream "Stream" is currently a global veriable.
The line
FoundStr.CopyFrom(Stream, (EndPos - StartPos));
does not work.
I have the correct position as I have put in the line
Stream.Read(Buffer1[0],250);
in its place and the contents of Buffer1 is correct.
Any ideas what I am doing wrong?
procedure TForm1.GetDescription(StartPos: Int64; S: String);
var
Buffer1, Buffer2: array[0..254] of Char;
FoundStr : TMemoryStream;
EndPos : Int64;
begin
Description_RE.Clear;
FillChar(Buffer1, 255, #0);
FillChar(Buffer2, 255, #0);
StrPCopy(@Buffer2, S);
FoundStr := TMemoryStream.Create;
Stream.Position := StartPos;
Stream.Read(Buffer1[0],Length(S));
while (not CompareMem(@Buffer1,@Buffer2,Length(S))) do
begin
if Stream.Position = Stream.Size then exit;
Stream.Position := Stream.Position - (Length(S) - 1);
Stream.Read(Buffer1[0], Length(S));
end;
EndPos := Stream.Position - Length(S);
Stream.Position := StartPos;
FoundStr.CopyFrom(Stream, (EndPos - StartPos));
Description_RE.Lines.LoadFromStream(FoundStr);
FoundStr.Free;
end;