Filtering TDialogButtons

I would like to filter the list of icons in the TDiagramButton control. My client has hundreds of custom shapes and needs to filter the list by partial names of the shapes.

There is ShowAllObjects, and DiagramCategories (not that there is help about this feature), but I need something that will filter in a different way, or at least search for an icon by partially matching its name. How can I accomplish this?

Unfortunately there is no easy way to do so with the existing TDiagramButtons component.

The current way is to indeed use manage the existing registered classes (in RegDControlList), by adding/removing controls to it, or changes its categories, and then calling TDiagramButtons.Populate method.

I have already written my own library database filer so that user designed symbols can be stored in a database. If population is done through a library control I could add filtering to the library, then re-populate the TDiagramButtons.

Alternatively, is there some way of accessing all the registered blocks and/or lines? If I can combine my custom, library loaded symbols with the registered blocks and lines I can add them to a grid control, and use the grid to filter and search. Obviously I would need to emulate many (if not all) of the actions of the TDiagramButtons control; but that may be an easier solution than adding a filter capability to the TDiagramButtons control.

Yes, they are available in the global variable RegDControlList. As I said, all the population of TDiagramButtons is based on what is there in that object. You can read it to build your own custom palette toolbar, or you can modify it and then call Populate method of diagram buttons to repaint it.

It's working good so far, but only the user constructed symbols have glyphs that I can collect using

RegDControlList.Items[i].Glyph

How to I get the glyphs of registered blocks and lines?

For built-in blocks, the icons are in bitmap resources which name is the id of the block (usually the class name) prefixed by BLK_. Here is the relevant code in TDiagramButtons for your reference:

    if aUseGlyph then
      aBitmap.Assign(aGlyph)
    else
    begin
      {$WARNINGS OFF}
      aHInstance := FindClassHInstance(aClass);
      aID := UpperCase('BLK_' + aID);
      aBitmap.Handle := LoadBitmap(aHInstance,PChar(aID));
      {$WARNINGS ON}

      {$WARNINGS OFF}
      aHInstance := FindClassHInstance(TDiagramButtons);
      if aBitmap.Handle = 0 then
      begin
        aClassName := UpperCase('BLK_' + aClass.ClassName);
        aBitmap.Handle := LoadBitmap(aHInstance,PChar(AClassName));
      end;
      {$WARNINGS ON}

      if aBitmap.Handle = 0 then
        aBitmap.Handle := LoadBitmap(aHInstance, 'BLK_TCUSTOMDIAGRAMBLOCK');
    end;
1 Like