function TEditorForm.SaveBinaryReg(
const aFileName:
string): boolean;
var
MemoryStream: TMemoryStream;
WideCharP: PWideChar;
TextSize: Cardinal;
BufferSize: Cardinal;
begin
result := False;
MemoryStream := TMemoryStream.Create;
try
MemoryStream.Clear;
// Detect Size
TextSize := Length(SynEditor.Lines.Text);
BufferSize := TextSize*SizeOf(WideChar);
// Write MemoryStream
GetMem(WideCharP, BufferSize);
try
StringToWideChar(SynEditor.Lines.Text, WideCharP, TextSize);
MemoryStream.
Write(WideCharP^, BufferSize);
finally
FreeMem(WideCharP, BufferSize);
end;
// Write File
try
MemoryStream.SaveToFile(aFileName);
result := True;
except
on E:
Exception do
ExpMessageDlg(Application.MainForm, Format(SFileCreateError, [aFileName, E.
Message]),
mtWarning, [mbOk], 0);
end;
finally
FreeAndNil(MemoryStream);
end;
end;