Attach icons to Blocks

Hello wigner
In order to attach an con image to my new created "TVectorBlock" I used the following as you suggested to me in an earlier post:

RegDcontrolList.FindById('TVectorBlock').Glyph.Assign(MyIcon.Picture);
RegDcontrolList.FindById('TVectorBlock').useglyph:=true;
AtDiagram1.RefreshToolbars;

Every thing is ok so fare. And I can see the glyph transfered to my Block...
However I noticed that the glyph is not saved in a permanent way when I close the program.
How can I handle that without using bitmaps resource file?
Thanks in advance

What do you mean by glyph not being saved in a permanent way? The glyph is not part of the block itself, it's not save together with the diagram. It's part of the block registration, available in the toolbar.

Every time you launch your application, you have to register the glyph so Diagram Studio knows what glyph to use for each block type.

Please it might be my request is obvious to you, but my skills in this field are limited!!
By code, I could attach an icon to a block I created. I can see the block on the toolbar and in the Fbuttons panel with this icon.
HOW AND WHERE CAN I REGISTER THE GLYPH SO IT IS RELOADED EACH TIME THE PROGRAM OPENS?
Please help!

I still don't understand:

By code, I could attach an icon to a block I created. I can see the block on the toolbar and in the Fbuttons panel with this icon.

If you were able to do that, then you should just do that. You did it. What else you want to do?

Hello again. Is seems you begin to be angry on me. I will try for the last time to explain my problem ,if though I could not succeed to explain my self', then I ask you to close the post!'

  1. I created a TPulley block....
  2. I registered the Block with the code RegisterDControl(TPulley, '', 'Pulley', 'Mechanics');
  3. In the TDiagrambuttons panel(Also in the DiagramToolBar1) I can see a white square without an icon that correspond to shape of my created block.
  4. by pressing on this White Square I could bring the Pulley block to appears on the atdiagram1.
    So far so good!!
  5. I also found a way to transfer the icon of the pulley appearing on the screen to the white empty square in the DiagramButtons(Also in the DiagramToolbar); Using the following code:

procedure TFScienceStudio.Button8Click(Sender: TObject);
var Reg:TRegDControl;
begin
Reg:=RegDcontrolList.FindById('TPulley');
Reg.Glyph.Assign(MyIcon.Picture);
Reg.useglyph:=true;
FDiagram.RefreshToolbars;
end;


Please look at the image attached! So far so good!
When I try to close the program and reopen it the icon disappears.
My question is: Is there a way to to get this icon saved some where(in the diagramToolbar for example) so that my program loads it automatically each time it opens without the need of the above piece of code?
I appreciate your patience on me
Thank you very much

Hi @Wakim_Bishara1, I'm not angry. I was just not able to understand what was happening. Your now more detailed information clarified it, and explains the source of confusion.

What you did, as I said, is exactly what you need to achieve what you want. This is the code you should run in the initialization of your application, right after you call RegisterDControl:

var Reg:TRegDControl;
begin
  RegisterDControl(TPulley, '', 'Pulley', 'Mechanics');
  Reg:=RegDcontrolList.FindById('TPulley');
  Reg.Glyph.Assign(TheIconYouWant);
  Reg.useglyph:=true;
  FDiagram.RefreshToolbars;
end;

As you see, is exactly the code you used. The exception is that I replaced MyIcon.Picture by TheIconYouWant. You must have the block icon in advance. Save it somewhere, a bmp/png in a file, or resource. Load it and use the exact code you used to set the block icons. That's how's supposed to be.

1 Like

Thank you very much

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.