MemoryStream`e String değişkeni atıp geri çağırma
Program esnasında oluşturduğumuz TMemoryStream kontrolüne istediğimiz bir string değişkeni atıp istendiğinde geri almak için aşağıdaki yöntem kullanılabilir.
procedure TForm1.Button1Click(Sender: TObject);
var
SourceString: string;
MemoryStream: TMemoryStream;
begin
SourceString := `Hello, how are you doing today?`;
MemoryStream := TMemoryStream.Create;
try
// Write the string to the stream. We want to write from SourceString`s
// data, starting at a pointer to SourceString (this returns a pointer to
// the first character), dereferenced (this gives the actual character).
MemoryStream.WriteBuffer(Pointer(SourceString)^, Length(SourceString));
// Go back to the start of the stream
MemoryStream.Position := 0;
// Read it back in to make sure it worked.
SourceString := `I am doing just fine!`;
// Set the length, so we have space to read into
SetLength(SourceString, MemoryStream.Size);
MemoryStream.ReadBuffer(Pointer(SourceString)^, MemoryStream.Size);
Caption := SourceString;
finally
MemoryStream.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
SourceString: string;
MemoryStream: TMemoryStream;
begin
SourceString := `Hello, how are you doing today?`;
MemoryStream := TMemoryStream.Create;
try
// Write the string to the stream. We want to write from SourceString`s
// data, starting at a pointer to SourceString (this returns a pointer to
// the first character), dereferenced (this gives the actual character).
MemoryStream.WriteBuffer(Pointer(SourceString)^, Length(SourceString));
// Go back to the start of the stream
MemoryStream.Position := 0;
// Read it back in to make sure it worked.
SourceString := `I am doing just fine!`;
// Set the length, so we have space to read into
SetLength(SourceString, MemoryStream.Size);
MemoryStream.ReadBuffer(Pointer(SourceString)^, MemoryStream.Size);
Caption := SourceString;
finally
MemoryStream.Free;
end;
end;