Simple_Application_Framework_for_VCL[10]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 zblue78 的 blog

the last step is to create the toolbars and bar items needed, place the bar items where required and bind them to vcl actions at design-time. that is it.

summary

as you can see, we did all modifications to the main module only and the task was quite easy. how do you migrate from one menu&toolbar library to another in your application? i guess it could be a real pain.

here is the link to the source code of the application written in delphi. you should have the developer express expressnavbar control and the expressbars library installed in your environment to be able to compile and run this demo.

create developer express grid module

we have greatly improved the appearance of our application by replacing the standard controls with the developer express xtranavbar and xtrabars libraries. now it is time to think about improving our framework in terms of module content. in your application, you are unlikely to inherit the "end-user" module from the custommodule directly. in most applications, there are usually several modules that show objects/records in a list. generally, we use a grid control for this purpose and this is typically the central control in an application. you will need to write code around the grid, e.g. showing/hiding the column customization window etc. of course, it makes no sense to code this functionality for every module containing a grid control. we will create a customgridmodule module. the developer express expressquantumgrid will be located on this module. as well as grid actions, we will introduce export actions. although we will add support for export actions in the base module, by default these actions will be disabled, so actual grid modules have to override methods to re-enable them.

to introduce the grid module, we need to make modification to the main form, the action datamodule and create a new module: customgridmodule. it has to be derived from custommodule.

we need to modify the main form and action data module to add actions, expressbars items and link actions to expressbars items as we have already done earlier. the process is absolutely the same.

a more interesting task is to add support for export actions into custommodule. by default, the export actions will then be visible to all modules, but they will be disabled. to enable them, the module have to override two methods: supportedexporttypes and doexport. here is the code that implements the export action support in custommodule.

[delphi]

  texporttype = (ethtml, etxml, etxls, ettext);
  texporttypes = set of texporttype;

  tfrmcustommodule = class(tframe)
    …
  protected 
    …
    // the descendant classes have to override this method to register the actions supported 
    procedure registeractions; virtual;
    // do the export based on the export type 
    procedure doexport(aexporttype: texporttype; const afilename: string); virtual;
    // returns the supported export types 
    function supportedexporttypes: texporttypes; virtual;
    …
  end;

the implementation of export actions in the customgridmodule is quite obvious:

[delphi]

procedure tfrmcustomgridmodule.doexport(aexporttype: texporttype; const afilename: string);
begin 
  case aexporttype of 
    ethtml: exportgrid4tohtml(afilename, grid);
    etxml: exportgrid4toxml(afilename, grid);
    etxls: exportgrid4toexcel(afilename, grid);
    ettext: exportgrid4totext(afilename, grid);
  end;
end;

function tfrmcustomgridmodule.supportedexporttypes: texporttypes;
begin 
  result := [ethtml, etxml, etxls, ettext];
end;

to implement grid actions, we will use the tcxgridoperationhelper class that you will find in the cxgriduihelper.pas file that is shipped with the product. it implements standard grid operations for different views.

[delphi]

constructor tfrmcustomgridmodule.create(aowner: tcomponent);
begin 
  inherited create(aowner);
  fgridoperationhelper := tcxgridoperationhelper.create(self);
  fgridoperationhelper.grid := grid;
  fgridoperationhelper.onupdateoperations := dogridupdateoperations;
  fgridoperationhelper.oncustomizationformvisiblechanged := dogridupdateoperations;
end;

procedure tfrmcustomgridmodule.registeractions;
begin 
  inherited registeractions;
  registeraction(appactions.actiongridgrouping, doactiongridgrouping);
    …
  registeraction(appactions.actiongridcolumnscustomization, doactiongridcolumnscustomization);
end;

procedure tfrmcustomgridmodule.updateactionsstate;
begin 
  inherited updateactionsstate;
  appactions.actiongridgrouping.enabled := fgridoperationhelper.isoperationenabled[grop_showgroupingpanel];
  appactions.actiongridgrouping.checked := fgridoperationhelper.isoperationshowing[grop_showgroupingpanel];
  appactions.actiongridcolumnscustomization.enabled := fgridoperationhelper.isoperationenabled[grop_showcolumncustomizing];
  appactions.actiongridcolumnscustomization.checked := fgridoperationhelper.isoperationshowing[grop_showcolumncustomizing];
end;

function tfrmcustomgridmodule.focusedview: tcxcustomgridview;
begin 
  result := grid.focusedview;
end;

procedure tfrmcustomgridmodule.doactiongridgrouping(action: tbasicaction);
begin 
  fgridoperationhelper.doshowgroupingpanel(not fgridoperationhelper.isgroupingpanelshowing);
end;

procedure tfrmcustomgridmodule.doactiongridcolumnscustomization(action: tbasicaction);
begin 
  fgridoperationhelper.doshowcolumncustomizing(not fgridoperationhelper.iscolumnscustomizingshowing);
end;

procedure tfrmcustomgridmodule.dogridupdateoperations(sender: tobject);
begin 
  updateactionsstate;
end;

本文关键:Simple_Application_Framework_for_VCL
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top