The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,854 other subscribers

Archive for the ‘Delphi’ Category

Delphi commandline oddity with double-quoted arguments

Posted by jpluimers on 2011/07/14

Boy, I was wrong. Somewhere in the back of my head I knew it.

ParamStr goes from zero (the name of the EXE) through ParamCount (the last parameter). Duh :)

 

I’ll keep this so you can have a good laugh:

 

When you add double quoted arguments to the commandline of your Delphi app, strange things can happen: the first parameter seems to be gone, while it is there.

It appears that the ParamCount/ParamStr logic fails here, and cannot be repaired because of backward compatibility.

Lets look at this commandline:

“..\bin\DumpCommandLine.exe” “C:\Program Files\test.xml” “C:\Program Files\meMySelfAndI.xml”

The demo code below will output something like this:

ParamCount:     2
ParamStr():
0       C:\develop\DumpCommandLine\bin\DumpCommandLine.exe
1       C:\Program Files\test.xml
CommandLine:
"..\bin\DumpCommandLine.exe" "C:\Program Files\test.xml" "C:\Program Files\meMySelfAndI.xml"
CommandLineStrings.Count:       3
CommandLineStrings[]:
0       ..\bin\DumpCommandLine.exe
1       C:\Program Files\test.xml
2       C:\Program Files\meMySelfAndI.xml

You see that regular ParamCount/ParamStr calls will mis the “C:\Program Files\test.xml” parameter.
But getting it through CommandLineStrings will correctly get it.

This is the dump code:

unit CommandlineDemoUnit;

interface

procedure DumpCommandLineToConsole;

implementation

uses
  Classes, CommandlineUnit;

procedure DumpCommandLineToConsole;
var
  CommandLineStrings: TStrings;
  I: Integer;
begin
  Writeln('ParamCount:', #9, ParamCount);
  Writeln('ParamStr():');
  for I := 0 to ParamCount - 1 do
    Writeln(I, #9, ParamStr(I));
  Writeln('CommandLine:');
  Writeln(CommandLine);
  CommandLineStrings := CreateCommandLineStrings();
  Writeln('CommandLineStrings.Count:', #9, CommandLineStrings.Count);
  Writeln('CommandLineStrings[]:');
  try
    for I := 0 to CommandLineStrings.Count - 1 do
      Writeln(I, #9, CommandLineStrings[I]);
  finally
    CommandLineStrings.Free;
  end;
end;

end.

And this the code to get the CommandLine and CommandLineStrings, which will fill a TStrings result using the CommaText property (it uses a default QuoteChar of of double quote #34 and Delimiter of space #32, this will work nicely):

unit CommandlineUnit;

interface

uses
  Classes;

function CommandLine: string;
function CreateCommandLineStrings: TStrings;

implementation

uses
  Windows;

function CommandLine: string;
begin
  Result := GetCommandLine();
end;

function CreateCommandLineStrings: TStrings;
begin
  Result := TStringList.Create();
  Result.CommaText := CommandLine;
end;

end.

Note that you need to manually free the TStrings object to avoid memory leaks.

–jeroen

Posted in Delphi, Development, Software Development | 13 Comments »

Code Quality: the rate of WTFs

Posted by jpluimers on 2011/07/06

OSnews has an interesting view on code quality: the number of WTFs/minute.

I know it is from 2008, but it is so true, so I’m glad I re-found it.

–jeroen

via: wtfm.jpg (500×471).

Posted in .NET, Agile, Delphi, Development, Opinions, Software Development | Leave a Comment »

winapi – Best way to do non-flickering, segmented graphics updates in Delphi? – Stack Overflow

Posted by jpluimers on 2011/07/05

Recently, Jon Lennart Aasenden (of Surface Library fame) asked a nice winapi – Best way to do non-flickering, segmented graphics updates in Delphi question on StackOverflow.

Though the question is marked Delphi, the boundaries and solution very generic, and apply to any graphics library or GUI you develop: Windows, Mac, iOS, et cetera:

  • Avoid double buffering when using GUI connections
  • Draw only what you need
  • Avoid redrawing whenever possible (for instance by letting the OS perform scrolling for you)
–jeroen

Posted in .NET, Delphi, Development, Software Development, xCode/Mac/iPad/iPhone/iOS/cocoa | 2 Comments »

The importance of static links on the web: many (really) old links still work

Posted by jpluimers on 2011/06/30

Doing a re-haul of a Delphi project from almost 15 years ago, and some modifications a few year later, I came across a list of favourites I used back then.

It also reminded me when beginning that project, there was no Google Search; you had Yahoo SearchHotBot and later on Northern Light, but AltaVista was the best.
Finding your way around was much harder, but luckily later on Google Search was there :)

So here is a sample of how static the web is:

Few suffer from link rot: I was pretty amazed that most of the links still work!

–jeroen

Posted in Delphi, Development, Power User, Software Development | 4 Comments »

Weaving: Source code, IL, ByteCode, Native

Posted by jpluimers on 2011/06/28

Weaving extends your program adding new functionality.

It can be at different levels for difference purposes (AOP, Debugging, Automated Testing, etc).

This .net – What is IL Weaving? question on StackOverflow contains a few pointers to interesting reading material.

–jeroen

Posted in .NET, Debugging, Delphi, Development, Software Development | Leave a Comment »

Delphi and COBOL syntax highlighters

Posted by jpluimers on 2011/06/21

I’ve been working on a project that uses both COBOL and Delphi.

For documentation purposes, Syntax Highlighted code makes your code so much easier to read.

Delphi has GExperts for source code export (in either HTML or RTF), but it took me a while to find a good syntax highlighter for COBOL.

I finally found a COBOL syntax highighter at tohtml.com: it exports to HTML.

I’m glad I found that site, as they have a ton of syntax highlighters, divided into groups.

Quite amusing to see COBOL classified as ‘rare’ (given that it has one of the largest code bases in the world).

This is what they support:

  • main: Java
  • main: C
  • main: Visual Basic
  • main: PHP
  • main: C++
  • main: Perl
  • main: Python
  • main: C#
  • main: Ruby
  • main: JS.NET
  • main: VB.NET
  • main: Pascal
  • main: JavaScript
  • inet: html
  • inet: css
  • inet: css for html
  • inet: css for svg
  • inet: jsp
  • inet: xhtml transitional
  • inet: xhtml strict
  • inet: xhtml frameset
  • inet: asp – VBScript
  • inet: asp – JavaScript
  • inet: asp – PerlScript
  • inet: SVG 1.0
  • inet: ColdFusion
  • inet: ActionScript
  • inet: VBScript
  • xml: xml
  • xml: dtd
  • xml: xslt 1.0
  • xml: XML Schema
  • xml: Relax NG
  • xml: xlink
  • database: Clarion
  • database: Clipper
  • database: FoxPro
  • database: SQLJ (Java sql)
  • database: Paradox
  • database: SQL, PL/SQL
  • database: MySQL
  • scripts: Batch/Config.sys/NTcmd
  • scripts: sh/ksh/bash script
  • scripts: Apache httpd.conf
  • scripts: Config, INI and CTL
  • scripts: Colorer HRC
  • scripts: Colorer HRD
  • scripts: Delphi form
  • scripts: Java Compiler Compiler
  • scripts: Java properties
  • scripts: Lex
  • scripts: YACC
  • scripts: makefile
  • scripts: Regedit
  • scripts: Resources
  • scripts: TeX
  • scripts: OpenVMS DCL
  • scripts: VRML
  • scripts.install: RAR Install Script
  • scripts.install: Nullsoft Install Script
  • scripts.install: InnoSetup script
  • scripts.install: IS script
  • rare: ASM
  • rare: 1C
  • rare: Ada
  • rare: ABAP/4
  • rare: AutoIt 2.x
  • rare: AWK
  • rare: Dssp
  • rare: ADSP-21xx Asm
  • rare: Baan
  • rare: Cache/Open-M
  • rare: Cobol
  • rare: Eiffel
  • rare: Forth
  • rare: Fortran
  • rare: Haskell
  • rare: Icon
  • rare: IDL
  • rare: Lisp
  • rare: MatLab
  • rare: Modula2 and Oberon2
  • rare: PicAsm
  • rare: Rexx
  • rare: Standard ML
  • rare: OCaml
  • rare: Tcl/Tk
  • rare: Sicstus Prolog
  • rare: Turbo Prolog
  • rare: Verilog HDL
  • rare: VHDL
  • rare: z80asm
  • rare: asm80
  • rare: 8051 asm
  • rare: AVR asm
  • other: files.bbs
  • other: Diff/Patch
  • other: message
  • other: plain text
  • other: default type

--jeroen

Posted in COBOL, Delphi, Development, LISP, Software Development | 6 Comments »

SVN tree to source code of Marco Cantu’s Delphi Books

Posted by jpluimers on 2011/06/09

If you love the Delphi books by Marco Cantu as much as I do, then you certainly will love that Marco has created a public SVN repository at code.marcocantu.com containing all the samples of his Delphi 6, 7, 2007, 2009, 2010 and XE books.

Way to go Marco!

–jeroen

Posted in Delphi, Development, Software Development | 2 Comments »

GExperts version 1.35 was released on June 5th, 2011

Posted by jpluimers on 2011/06/08

Earlier this week, the new GExperts 1.35 Release got published: a free set of expert extensions supporting Delphi 6 through XE.

It is an incremental release has a few new features of which I like the new subgroup support in the Grep Search extensions most.

Now hopefully, Thomas Müller will release an experimental GExperts build of version 1.35 soon: his experimental builds integrate a source code formatter that works across many Delphi versions and often formats better than the one included in Delphi 2010 and up.

–jeroen

Posted in Delphi, Development, Software Development | 4 Comments »

Delphi sorcery – great new blog by Stefan Glienke: DataBinding, MEF, Lamda Expressions and more

Posted by jpluimers on 2011/06/07

I just came across the great new Delphi sorcery blog by Stefan Glienke from Soest, NRW, Germany.

He uses some cool new features recently introduced into Delphi for new ways of DataBindingYield-Return, Delphi Lambda Expressions, Delphi Dependency Injection with MEF and more.

Sample code is at his Delphi Sorcery Google Project.

I hoped that somebody would do all that, as this shows the real power of what Delphi can do.

Now it’s there for

–jeroen

Posted in Delphi, Development, Software Development | 2 Comments »

Delphi Win32 talking to .net – Different WSDL ASMX,WCF web-services – Stack Overflow

Posted by jpluimers on 2011/05/31

An interesting question on Stackoverflow.com: .net – Different WSDL ASMX,WCF web-services – Stack Overflow.

The answer is simple when you know it: flatten the WSDL that comes from WCF.

Note that Delphi Win32 is not the only client having these issues, as Elton Stoneman shows on his blog and the WCFExtras toolkit for WCF that allows for single WSDL export.

–jeroen

Posted in .NET, Delphi, Development, Software Development | Leave a Comment »