Monday, 3 February 2014

Using TObjectList in Generics.Collections

In 2009 a new TObjectList was introduced in Generics.Collections, the old TOjectList was still available in the Contnrs unit, but the new one was more strongly typed and you need to specify the class of object the the list will be populated with. This means a reduction in type casting. Here is an example of how to use it:

TMyListClass = class(TObject)
   private
        FEntries: TObjectList<TMyEntry>;
   public
        property Entries: TObjectList<TMyEntry> read FEntries                write FEntries;

        function GetEntry(aIndex: integer):TMyEntry; 

        constructor Create;
        destructor Destroy; override;         
   end;

implementation

constructor TMyListClass.Create;
begin
    inherited Create;
    FEntries := TObjectList<TMyEntry>.Create();
end;

destructor TMyListClass.Destroy;
begin
    FEntries.Free;
    inherited Destroy;
end;

function TMyListClass.GetEntry(aIndex: integer):TMyEntry;
begin
   // You don't need to typecast
   // Old way 
   // if (FEntries.Items[aIndex] is TMyEntry) then
   //    Result (FEntries.Items[aIndex] as TMyEntry; 
   Result := FEntries.Items[aIndex];
end; 



Monday, 27 January 2014

DevExpress Grid Modify Date Header Filter

In a DevExpress grid I needed to remove options from the filter that is available from the column header. Because the header related to the date column it put in a load of filter options that I did not require. I managed to do this by creating an OnGetFilterValues event:

MyGridView.Columns[MyGridView.GetColumnByFieldName('MY_DATE_FIELD').Index].OnGetFilterValues := cxGridGetFilterValues;

Then I put the following code in the procedure:

procedure MyFrm.cxGridGetFilterValues(Sender: TcxCustomGridTableItem; AValueList: TcxDataFilterValueList);

    procedure DeleteFilterEntry(AValue: Variant);
    begin
        AValueList.Delete(AValueList.FindItemByKind(fviSpecial,               AValue));
    end;
begin
      DeleteFilterEntry(foYesterday);
      DeleteFilterEntry(foToday);
      DeleteFilterEntry(foTomorrow);

      DeleteFilterEntry(foNext7Days);
      DeleteFilterEntry(foNext14Days);
      DeleteFilterEntry(foNext30Days);
end;

There are more filter options that could be removed, it just a matter of looking at the unit that contains the constants.

Tuesday, 7 January 2014

Value and reference types

Value types
Live on the stack. Examples of these types are the simple types like integers, and records

Reference types
Live on the heap. Examples of these types are objects, interfaces and pointers.

Strings are unusual because they live on both the stack and heap, behavior is on the stack and the storage is on the heap.



Tuesday, 31 December 2013

Best Delphi Calendar Planner Component?

I current use a very out of date calendar/planner component in part of the software I develop. I have been looking for something to replace this and can only see 2 possible candidates:

  • DevExpress VCL Calendar
  • TMS Software TPlanner component.
Does anyone know of any other components, or have experience of these and can give advice on which is best?

The requirements for the component are:

  • Needs a month, week and day view, it is possible that this changes to just week view.
  • Different types of entries into the calendar, with different colours.
  • Single day view, with option to specify what is displayed in the header.
  • Need to dynamically create multiple instances of the calendar, or some way of displaying multiple calendars similar to MS Outlook.
  • Drag and drop functionality

Tuesday, 29 October 2013

Running Delphi XE in Parallels Desktop on iMac

I currently use Parallels Desktop to run a Windows VM on my iMac, this works great for most applications, however there are a couple of issues I have found with Delphi.
  1. The some of the shortcut keys do not seem to work.
  2. Function keys required pressing FN key as well as function key.
  3. For some reason the cap locks gets pressed on the VM, meaning I have to open the on-screen keyboard to remove it.
The second issue is easy to fix with going to the system preferences and selecting the use all F1.. option.


Monday, 28 October 2013

Delphi XE5 - The quickest way C# developers can produce Apps

With Delphi XE5, a software developer can produce apps for both iOS and Android from the same code base. But which developers will want to do this?

If you are an iOS developer, it is most likely you are comfortable just developing app for Apple devices and that the company you work for employs Android developers for the Android version and vis versa. And you have no need or want to learn a new language to get the same results.

However, if you are a C# developer then Delphi XE5 might be the quickest way to develop Apps. I found moving from Delphi to C# very easy and after 1 day was developing C# web services. I also found it easy switching back to Delphi after using C# for some months.

So if you are a .Net developer then I would recommend you at least have a look at Delphi XE5.

Thursday, 22 August 2013

DevExpress Quantumgrid Header Height

I have had a problem recently using a DevExpress Quantum Grid which has the column filters enabled and also the ability to drag and drop. I needed a way to get the header height so it would ignore the begindrag. The after trying a few things this is the best way I found to get the header height.

iHeaderHeight := GridView.ViewInfo.HeaderViewInfo.Bounds.Bottom -
      GridView.ViewInfo.HeaderViewInfo.Bounds.Top;