const szChar = SizeOf(Char); ///this functions are pretty fast and you can easily find other usage for them./// saves a string to a file /// procedure StringToFile(const s: string; const FileName: string); var FileStream: TFileStream; begin FileStream := TFileStream.Create(FileName, fmCreate); try FileStream.WriteBuffer(Pointer(s)^, (Length(s) * szChar)); finally FreeAndNil(FileStream); end; // try end; ////// returns the content of the file as a string /// function StringFromFile(const FileName: string): string; var FileStream: TFileStream; begin FileStream := TFileStream.Create(FileName, fmOpenRead); try SetLength(Result, (FileStream.Size div szChar)); FileStream.ReadBuffer(Pointer(Result)^, FileStream.Size); finally FreeAndNil(FileStream); end; // try end;
Hosting Preview Handlers in Delphi VCL Applications
-
In this post i will show you, how you can host an existing Preview Handler
in your Delphi VCL App. Preview handlers are a lightweight and read-only
preview...
(Length(Result) * SizeOf(Char))
ReplyDeleteFixed, thank you for noticing, when I've posted this I was still using Delphi 7, but of course there's no excuse for writing bad code ;-)
ReplyDeleteAwesome. Exactly what I was looking for. Worked like a gem.
ReplyDeleteThis short and simple code really work like a gem!
ReplyDeleteI have made a large Front/End for reading and writing based on these tiny simple examples. It has opened up a new world of programming for me :)