Showing posts from October, 2012

Checking File Preambles and Watermarks

I'm constantly having to check the preambles of files for some kind of signature (or "watermark") to check or validate the file's format.I've re-invented the wheel many times over while doing this. Time, I thought, for a little helper routine or two.First, a little routine to check the next N bytes from a stream for a given sequence of bytes (the "watermark").functionStreamHasWatermark(constStm:TStream;constWatermark:arrayofByte):Boolean;varStmPos:Int64;Buf:arrayofByte;I:Integer;beginAssert(Length(Watermark)>0,'No "watermark" specified');Result:=False;StmPos:=Stm.Position;tryifStm.Size-StmPos<Length(Watermark)thenExit;SetLength(Buf,Length(Watermark));Stm.ReadBuffer(Pointer(Buf)^,Length(Buf));forI:=Low(Buf)toHigh(Buf)doifBuf[I]<>Watermark[I]thenExit;Result:=True;finallyStm.Position:=StmPos;end;end; Pass it a stream and an array containing the required "watermark" and the routine checks to see if the watermark exists…

New look blog

Just finished giving the blog a new look and feel. I hope it's clearer and less fussy than the previous version.The syntax highlighter styling has been switched to emulate the Delphi "Classic" theme, e.g.:procedureFoo;// example of highlighterShowMessage('The answer is '+IntToStr(42));end; So there we are then. Comments appreciated.

CodeSnip 4 Emerges

After a lot of development CodeSnip v4 has finally been released. You can get it from the CodeSnip Download Page or from SourceForge. Here's a list of the key new features and changes:Snippet HandlingNew "unit" and "class" snippet kinds that can include complete units and classes (and advanced records) in the database. Both can be test compiled and classes / advanced records can also be included in generated units.Snippets from both the main and user databases can now be duplicated. This is very useful if you have created a snippet and want to create another one that shares a lot of the source code, dependencies etc.The full range of Unicode characters can now be used for snippet names, descriptions etc., and for source code.There is now finer control over the control of warnings in generated code via the $WARN directive.The names of referenced units may now contain dots so that Delphi namespaces can be used.User InterfaceThe new multi-tab display can display de…