Debugging: Detecting that UI thread is blocked?

Debugging: Detecting that UI thread is blocked?

Update: The source for my quick and dirty MonitorUIResponse:

https://drive.google.com/file/d/0B1MyXorVzay9ZjFJc3B6VjI3MUU/view?usp=sharing

Does anyone know of a tool or method that can monitor and log the responsiveness of a UI?  I.e. flag occasions where the app is in “Not responding” mode for a period of time (1 sec or more) ?

I’m trying to track down a strange “lagginess” which doesn’t directly reflect in the debug out log.

TCustomAttribute and class internal types

TCustomAttribute and class internal types

Consider

Default = class(TCustomAttribute)

  DefaultVal: Integer;

  constructor Create(const aVal:Integer);

end;

TMyBaseClass = class(TObject)

public

   constructor Create; virtual;  // handles attributes

end;

// 1

TMyClass = class(TMyBaseClass)

public

  [Default(5)]

  Value: Integer;

end;

which is ok, versus

TMyBaseClass = class(TObject)

public

   type

      Default = class(TCustomAttribute)

        DefaultVal: Integer;

        constructor Create(const aVal:Integer);

      end;

   constructor Create; virtual;  // handles attributes

end;

// 2

TMyClass = class(TMyBaseClass)

public

  [Default(5)]  

W1025 Unsupported language feature: ‘custom attribute’

  Value: Integer;

end;

as well as

// 3

TMyClass = class(TMyBaseClass)

public

  [TMyBaseClass.Default(5)]  

E2010 Incompatible types: ‘TQuerySet’ and ‘TCustomAttribute’

  Value: Integer;

end;

Question

I can understand why //2 is a fail, since internal types have to be qualified, but why is //3 not a compatible type?

Update: Feature Request added to QP

https://quality.embarcadero.com/browse/RSP-13512

Database field to Generic T conversion?

Database field to Generic T conversion?

What is the cleanest and/or fastest way to convert a variant to a specific type T where T is limited to a simple type and comes from a database. 

uses

  rtti, Data.Db;

type

  TMyClass = class

     function Convert(const Field: TField):T;

  end;

How slow will using RTTI be? 

function TMyClass.Convert(const const Field: TField):T;

var

  v: TValue;

begin

  v := TValue.FromVariant(Field.AsVariant);

  Result := V.AsType;

end;

Am I better off using explicit conversions and/or casts per TFieldType or per Variant type? 

Just to explain why I want to do this: End goal is to have a non-visual “virtual query result grid” (i.e. rows by columns) where values are converted from database values to their “natural” Delphi types and then passed to other systems which will render the data with various decorators. Grid sizes can in theory vary from 10 rows by 20 columns to 5000 rows by 60 columns. 

I want to let go of the Dataset as fast as possible, and keep the results in this virtual structure. The hope is to be able to cut down amount of query to grid scaffolding code, among other things.

 

How do I check or change which set elements are present, using RTTI?

How do I check or change which set elements are present, using RTTI? I want to be able to check, add and remove T:TElements from ST:TElementSet.

type

  TElements = (elA, elB, elC);

  TElementSet = set of TElements;

  TMyClass = class

    property SetValue:ST;

  end;

Generics doesn’t enable me to tell the compiler that T is an enumerated type and that ST is a set of T.

RTTI enables me to identify the types as tkEnumeration and tkSet – but I am unsure if I can make a strict connection between the two using RTTI. That doesn’t really matter as I only need to twiddle the set bits by ordinal value.

The question is: Can I do this safely, using Generics and RTTI, and if so – how?

Examples and/or references to prior art would be appreciated.

http://stackoverflow.com/questions/33173534/how-do-i-check-or-change-which-set-elements-are-present-using-rtti

More SOAP header questions.

More SOAP header questions.

I posted a question on the official boards (https://forums.embarcadero.com/thread.jspa?threadID=117922&tstart=0), and so far it has been …crickets… – but I stumbed upon this post on SO: http://stackoverflow.com/questions/13751289/send-simple-strings-in-soap-header-in-delphi

which shows how to directly override TRemotable.ObjectToSoap to inject structures in the soap header. Unfortunately, it seems to be slightly more tricky to graft this into a WDSL document generated  unit (and lose/reintegrate the modifications each time you rebuild from a new WDSL file). 

ANY clues to how to do this smarter, would be appreciated.

Why is there no proper Soap Header handling in these classes, I wonder.  It seems that the WDSL importer is somewhat outdated, since it refers to SOAP 1.1 and 1.2 – considering 1.2 was renamed 2.0 about 8 years ago.

In addition – another question has arrived: How the heck can I convince it to add  _encoding=”utf-8″_ to the XML tag?

I do like learning new stuff, but it can be a hair-tearing experience at times.

WDSL spec to Soap object question.

WDSL spec to Soap object question.

According to the doc, the GetPartyByGLN should have a request header element – but I can’t see how to set it up in the generated code.

Does anyone know if the “Cannot unwrap” statement indicates a failure to build a complete interface?

  routerSoap = interface(IInvokable)

  [‘{0665B92C-D719-C758-A143-D08E93CE967A}’]

    // Cannot unwrap: 

    //     – More than one strictly out element was found

    // Headers: gepirRequestHeader:pIn, gepirResponseHeader:pOut

    function  GetPartyByGLN(const requestBody: GetPartyByGLN): gepirParty; stdcall;

Putting the generic in Generics?

Putting the generic in Generics?

Annoyance 1: 

  TThing = class

  private

    FThing: T;

    procedure SetThing(const Value: T);

  protected

    property Thing: T read FThing write SetThing;

  public

    procedure Configure(const aThing:T = nil); // *

  end;

* [dcc32 Error]: E2268 Parameters of this type cannot have default values

Why? It’s a class instance pointer, isn’t it?

Annoyance 2:

Types are simplified.

 

Unit 1

TAbstractColumn = class end;

TColumn = class(TAbstractItem) end;

TGridHelper = class(TList<TColumn>) end;

Unit 2 (uses 1)

TQueryGridHelper = class(TGridHelper) end;

TQueryStrGridHelper = class(TQueryGridHelper);

TQueryDBGridHelper = class(TQueryGridHelper);

note: TDBAdvGrid is a direct descendent of TAdvStringGrid

Unit 3 (uses 1 and 2)

procedure SomeClass.DefineColumns(const aHelper: ???);

If it is defined as 

procedure DefineColumns (const Helper: TQueryStrGridHelper);

I get: [dcc32 Error]: E2010 Incompatible types: ‘TQueryStrGridHelper’ and ‘TQueryDBGridHelper’ – which is understandable, but how can I specify an argument type for DefineColums which can take both a TQueryStrGridHelper and a  TQueryDBGridHelper?

Interfaces and self-destruction

Interfaces and self-destruction

I need the guidance of the gurus here. I’ve seen this mentioned before, but I can’t recall where.

I have a need for enumerating a list subset and I am wondering how I can do this while at the same time eliminating the housekeeping?

type

   TSelection = class(TList<TPair>);

Basically, I have various classes that I would like to return variations on a TSelection from a function.

type

  TSomeClass = class

     function AllActive(const filtervalue:sometype): TSelection;

  end;

var

  item: TPair;

begin

  for item in SomeClassInstance.AllActive(aFilter)

  do begin

     // something happens that concerns item

  end;

  // returned TSelection is automagically free’d here

end;

I actually want to use this in multiple levels, and there will be a multitude of TSelection returning functions – hence the desire for automated housekeeping.  Performance is not my primary concern – only flexibility and easy to read code.

Pointers to examples would be much appreciated – but I’d prefer not to pull in an entire class library – just a bare bone minimum.