PostMessage problem

PostMessage problem

For a long time, I’ve been using AllocatehWnd in the main thread to create handles for passing messages from background threads to the foreground thread.  

All the handles are created in the same location (during main thread startup), connecting to different handler procedures.  All messages are wm_user + unique number (from 1 to 140)

Recently, this stopped working for 3 of 4 handles, and I can’t for the life of me figure out why?  

The only messages I see, is a value of 28 (which is wm_ActivateApp) and it arrives on startup only) – and then I see one of my other registered messages from a specific background thread (wm_user + 121).

For the other threads, I see the postmessage being called, with the right handle and the right message – but it never arrives in the registered handler.

I’ve tried moving the message from wm_user + 1 to wm_user + 151 – in case something else was eating them.  No joy.

I’ve tried using only one handle, and calling all of the four handler methods from the common registered handler.  The same results.

Each handler do call DefWindowProc.  Can it be a component vendor that inserts a handler, but which fails to call DefWindowProc?

I need suggestions for possible causes, or for how to best drill down to the core of the problem, because I am stumped!

Duplicating a class instance

Duplicating a class instance

I’ve run into a strange problem, and I wonder if there is a solution out there.

I have working code that do this

  aCopy := TMyClass(Self.ClassType.Create);

The .Create will also eventually call .AfterConstruction – which poses a problem – as I do things in it which basically shouldn’t be done with the copy.

So – I add another constructor to the base class to set a flag to indicate it is a copy  – but – how do I invoke the other constructor?  

A cast like the one below, is not a viable solution, it seems – as I end up with a nil pointer AV.

  aCopy := TMyClass(Self.ClassType).AnotherCreate;

How do I invoke the right constructor in a clean and efficient way?

Any users of FireDAC TFDScript out there?

Any users of FireDAC TFDScript out there?

Scripts produced by ApexSQL Diff, which runs fine in SQL Server Management Studio, fail when run from a TFDScript.  I am trying to figure out if it is options related, or if it is an implementation problem.

Problem 1: Transaction handing causes an error:  

Exception class EMSSQLNativeException with message ‘[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL Server]A transaction that was started in a MARS batch is still active at the end of the batch. The transaction is rolled back.’. 

Problem 2: If I remove the begin tran at line 38/39 and reduce the script to only contain the create table part – it still fails silently. The spool output shows no errors, nor does any errors show in the FireDAC Monitor.  And yet – no table is created.

I also suspect that multiline /* block comments */ confuse the script analyzer.

Suggestions, anyone, particularly for Problem 2?

   

http://pastebin.com/dzR8T6fC

A FireDAC Date Mystery

A FireDAC Date Mystery

I have an app that connects to a MSSQL db through FireDAC and retrives a selection of log data, including the date and time of the logging in a datetime field.

I leave the app open for a longer period of time (about an hour, I think), then I refresh the view.

BAM! The dates show up as 1899.  For some reason, FireDAC has decided to forget how to get the datetime in the right format.

I suspect that is is related to a connection object that has lost it’s connection, but why can it reconnect and get data, and yet get the date format wrong?

 

XE6 to XE7 Update 1 Generics incompatibility.

XE6 to XE7 Update 1 Generics incompatibility.

I can’t say for sure if I ever tried this in XE7 first version, but I don’t think I did.

procedure TAbstractBaseFactory.CreateInner;

begin

  FInner := TBaseTypeClass(T).Create;  

end;

TBaseTypeClass(T).Create;  compiles and runs in XE6, but gives

[dcc32 Error] : E2010 Incompatible types: ‘T’ and ‘TAbstractBaseType’

in XE7.

Stefan Glienke – You showed me this trick for XE6 – any suggestions for XE7?

{code}

program CreateFromGenericTClassXE7;

{$APPTYPE CONSOLE}

{$R *.res}

uses

  System.SysUtils;

type

  TAbstractBaseType = class

  public

    Constructor Create; virtual;

    procedure DoSomething; virtual; abstract;

  end;

  TDescendantType = class(TAbstractBaseType)

  public

    procedure DoSomething; override;

  end;

type

  TBaseTypeClass = class of TAbstractBaseType;

type

  TAbstractBaseFactory = class abstract (TObject)

  private

    FInner: T;

    procedure SetInner(const Value: T);

  public

    constructor Create;

    procedure CreateInner; virtual;

    property Inner: T read FInner write SetInner;

  end;

{ TAbstractBaseFactory }

constructor TAbstractBaseFactory.Create;

begin

  Inherited;

end;

procedure TAbstractBaseFactory.CreateInner;

begin

  FInner := TBaseTypeClass(T).Create;  // [dcc32 Error] : E2010 Incompatible types: ‘T’ and ‘TAbstractBaseType’

end;

procedure TAbstractBaseFactory.SetInner(const Value: T);

begin

  FInner := Value;

end;

{ TDescendantType }

procedure TDescendantType.DoSomething;

begin

end;

{ TAbstractBaseType }

constructor TAbstractBaseType.Create;

begin

  Inherited;

end;

begin

  try

    { TODO -oUser -cConsole Main : Insert code here }

  except

    on E: Exception do

      Writeln(E.ClassName, ‘: ‘, E.Message);

  end;

end.