Posts

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"). function StreamHasWatermark ( const Stm : TStream ; const Watermark : array of Byte ) : Boolean ; var StmPos : Int64 ; Buf : array of Byte ; I : Integer ; begin Assert ( Length ( Watermark ) > 0 , 'No "watermark" specified' ) ; Result := False ; StmPos := Stm . Position ; try if Stm . Size - StmPos < Length ( Watermark ) then Exit ; SetLength ( Buf , Length ( Watermark ) ) ; Stm . ReadBuffer ( Pointer ( Buf ) ^ , Length ( Buf ) ) ; for I := Low ( Buf ) to High ( Buf ) do if Buf [ I ] <>

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.: procedure Foo ; // example of highlighter ShowMessage ( 'The answer is ' + IntToStr ( 42 ) ) ; end ; So there we are then. Comments appreciated.

CodeSnip 4 Emerges

Image
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 Handling New "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 Interface The new multi-tab displa