I’ve just had an epic derp moment…

I’ve just had an epic derp moment…

I inherited a form, add a few new controls and the related scaffolding.

Then I thought – wow – it would be nice to have a generic type property on that form – so I added to the declaration of the inherited form, and used the type in a couple of non visual related methods.  Saved, close the unit, instantiated the form elsewhere, using the appropriate T substitute.

The form shows up and goes BANG on the first new control reference in the code.  It was nil. All the new controls were nil.

I open the new form – or rather I try: Parent not found – so I can’t open the form designer.

Turns out that adding a generic wasn’t such a good idea after all.

Interesting that it compiled, really – considering the visual inheritance was totally broken.

Edit: But it would have been super neat! 😛

The curse of the Project.res file

The curse of the Project.res file

We’ve switched to for our production code, and we had a lot of “fun” figuring out why our FinalBuilder produced .exe files did not run, but stopped with “The application has failed to start because its side-by-side configuration is incorrect.”  It turned out that FB8 used a default manifest from RS which looked looked like this

$(asmv3_application)

$(dependency)

$(trustInfo)

So – we tinkered with the settings and asked FB8 to load the manifest from the resource file. Nada. Zip. Zilch. It was not there.  It turned out that you had to compile locally, then commit the .res file to make the manifest appear. 

The Project.res files are always a bit of an annoyance, and we are perhaps a bit inconsequent how we resolve a conflict on SVN update – use local, or use theirs.  This means that it is a bit iffy what actually survives in the .res file.  In the end, we’ve ended up making individual .manifest.xml files for each app – and explicitly include it in the FinalBuilder configs.  This means that if we make modifications to the manifest somehow, we need to upload that file separately.

The .res file conflicts are a worse problem than two people making changes to a .dfm – as the .dfm is text and can be resolved – while the .res file in binary and not human readable.

It really is beyond me why there is no Project.rc file which includes 

Project.version.rc

Project.icon.rc

Project.themes.rc

Project.manifest.xml

and so forth.

That way, the .res file would be a compile-time thing (or even a thing of the past) – and the resource linker would assemble the various bits from their individual sources.

It would probably make it way easier for Finalbuilder to dig into the resources and/or override where needed and it would certainly make the VCS .res file conflicts a thing of the past.

RAD Studio XE7 Enterprise, Update 1 – Out of memory

RAD Studio XE7 Enterprise, Update 1 – Out of memory

Just to clarify how extensive my memory issues are… I often have to compile at least three of these apps when testing changes.  The server, the admin app, and the truck app.  

I can currently compile 2.5 apps before I have to restart the IDE:P

Switching between two apps, the leak is slightly slower – but I will run out.  

I usually end up doing something like this: 

– Exit IDE, Restart IDE

– Compile the two apps I won’t be debugging,

– Exit IDE, Restart IDE

– Compile the app I plan to debug

– Exit IDE, Restart IDE, Start the other two apps outside the debugger.

– Run the app I plan to debug and hope the debugger doesn’t die on continue from breakpoints

…and that’s how the day passes… Dozens and dozens of restarts… and that’s on a good day.

Edit: IDE tweaks:

* No Castalia. 

* -noparser on command line

* Error Insight disabled

I certainly hope you are addressing this for the next major release, Marco Cantù 

Guess the output of this program.

Guess the output of this program.

Is this three Delphi bugs for the price of one?

Compiler mentions: 

[dcc32 Hint] WeirdCaseConstruct.dpr(11): H2077 Value assigned to ‘Handled’ never used

1. If statement inside case – after ELSE option?

2. Handled is actually used

3. else Test(4) is never called

 XE7.1 (32-bit, Windows)

program WeirdCaseConstruct;

{$APPTYPE CONSOLE}

{$R *.res}

uses

  System.SysUtils;

procedure Test(const Value: Integer);

var

  Handled: Boolean;

begin

  Handled := True; // <- Hinted

  case Value of

    1: writeln(‘One’);

    2: writeln(‘Two’);

    else Handled := False;

    if not Handled

     then Writeln(Value, ‘ is unhandled’)

      else Test(4);

  end;

end;

begin

  Test(1);

  Test(3);

  Write(‘Press Enter’);

  Readln;

end.

type

type

  TMyEnum = (One, Two, Three);

  TMyObject = class

  public type

    TItems = array[TMyEnum] of String;

  private

    FItems: TItems;

  public

    property Items:TItems read FItems write FItems; default;

  end;

 [dcc32 Error] E2132 Default property must be an array property

There probably is a good reason for this, but I am still annoyed 😛

ShFileOperation fails with error 2 (file not found), then error 87 (invalid parameter).

ShFileOperation fails with error 2 (file not found), then error 87 (invalid parameter).  Filename and pathname is correct.  Sometimes it works, sometimes, it doesn’t.  Can’t see the pattern.  Juggling all the flags doesn’t work…  WTF!?

Reading the documentation again… oh…

SourceFileName := SourceFileName + #0;

TargetPath := TargetPath + #0;

I guess they really meant it when they said to double 0 terminate the strings… problem solved.

Anonymous Methods and Captures in VCL

Anonymous Methods and Captures in VCL

Found an interesting debugging effect of captures today.  

Picture a frame with a list and a MyValueEdit (TAdvSpinEdit to be exact).  So, I’d made a bad decision to check the MyValueEdit.FloatValue in an anon method which was looped for selected elements in the list. 

Firstly, the value was wrong.  Even though I believed I had edited the value before the loop – the captured MyValueEdit retained the original value.

Secondly, trying to inspect MyValueEdit inside the anon method, informed me rather sternly that “MyValueEdit” is unknown.

Note to self: When in an anonymous method, minimize references to local variables outside the method. Needless to say, I am also looking at doing a proper enumerator instead of a loop that takes an anon method.