Simple_Application_Framework_for_VCL[8]

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

本文简介:选择自 zblue78 的 blog

add category and imageindex properties to the tmoduleinfo class. this is so we can save information about the category to which the module belongs and save its image index to show the appropriate image in the navbar control. here are the changes to the tmoduleinfo class:

[delphi]

// contains information about the module 
tmoduleinfo = class 
private 
    …
  fcategory: tcategoryinfo;
  fimageindex: integer;
    …
public 
  constructor create(const aname: string;
                     amoduleclass: tfrmcustommoduleclass;
                     acategory: tcategoryinfo;
                     aimageindex: integer = -1);
    …
  property category: tcategoryinfo read fcategory;
  property imageindex: integer read fimageindex;
end;

add categorycount, categories properties and addcategory, getcategorybyname methods to the tmoduleinfomanager class. it will allow us to add categories to our framework and retrieve them. we will use it in the next step.

[delphi]

//manage module info classes 
tmoduleinfomanager = class 
private 
    ...
  fcategorylist: tlist;

  function getcategorycount: integer;
  function getcategory(index: integer): tcategoryinfo;
    …
public 
    …
  // add new category 
  procedure addcategory(const aname: string; imageindex: integer);
  // returns the categoryinfo object by its name 
  function getcategorybyname(const name: string): tcategoryinfo;
  // register module module in the manager 
  procedure registermodule(const aname: string; amoduleclass: tfrmcustommoduleclass;
    acategory: tcategoryinfo = nil; aimageindex: integer = -1);

  // return the number of categories 
  property categorycount: integer read getcategorycount;
  property categories[index: integer]: tcategoryinfo read getcategory;
end;

the next step is to create navbar control groups, items and links accordingly to the modules registered in our application framework. we have to change the registermodules method in the main form unit

[delphi]

procedure tfrmmain.registermodules;
var 
  i: integer;
  anavbargroup: tdxnavbargroup;
  anavbaritem: tdxnavbaritem;
    …
begin 
  //go through all categories 
  for i := 0 to moduleinfomanager.categorycount - 1 do 
  begin 
    // add navbar group 
    anavbargroup := navbar.groups.add;
    // set navbar group caption 
    anavbargroup.caption := moduleinfomanager.categories[i].name;
    // set navbar group large image 
    anavbargroup.largeimageindex := moduleinfomanager.categories[i].imageindex;
    // use large images to show them in the navbar group 
    anavbargroup.usesmallimages := false;
  end;
  //go through all modules
  for i := 0 to moduleinfomanager.count - 1 do
  begin 
    // add new item into navbar 
    anavbaritem := navbar.items.add;
    // set navbar item caption 
    anavbaritem.caption := moduleinfomanager[i].name;
    // set navbar item image index 
    anavbaritem.smallimageindex := moduleinfomanager[i].imageindex;
    // use tag to identify the module 
    anavbaritem.tag := i;
    // add the item into appropriate navbar group 
    navbar.groups[moduleinfomanager[i].category.index].createlink(anavbaritem);
    …
  end;
end;

here is the code in navbar control's link click event handler:

[delphi]

procedure tfrmmain.navbarlinkclick(sender: tobject;
  alink: tdxnavbaritemlink);
begin 
  // show the module 
  showmodule(moduleinfomanager.items[alink.item.tag].name);
end;

the last step is to register categories in the application framework. it may be done, for example, in the initialization section of the main form

[delphi]

initialization 
  moduleinfomanager.addcategory('category 1', 0);

本文关键:Simple_Application_Framework_for_VCL
  相关方案
Google
 

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

go top