get name and properties fonts installed in windows on Delphi

Asked

Viewed 100 times

-1

And people blz?

I am wanting to get the property of fonts installed in windows using Delphi.

can already get all fonts in a listbox now I need to get the name and extension of the font.

//lista todas as fontes.
procedure TForm1.Button1Click(Sender: TObject);
begin
  ListBox1.Items := Screen.Fonts;
end;

//mostrar o nome fa fonte em um label.
procedure TForm1.ListBox1Click(Sender: TObject);
begin
  Label1.Caption := ListBox1.Items[ListBox1.ItemIndex];
  Label1.Font.Name := ListBox1.Items[ListBox1.ItemIndex];
end;

this is the code that I’m using to visualize all sources, now I need to take the name and extension of the same.

  • Wouldn’t it be better to list the files from the windows folder? Or if your "Screen" object already contains the information, you can add a pointer next to the item inserted in the listbox by retrieving the value and accessing the Screen object again.

  • So Leonardo, I need to get exactly the name and extension of the source, so it’s recording in a bank. Example: the Arial Font has in its property the name of this way "Arial.ttf" precise preaches this, because the system I am using needs to consume the source in this way"

  • You already have a list with the value "Arial.ttf" and etc? is the same list "Screen"?

  • this being my problem Leonado, and takes the value "Arial.ttf", I want to get just this value ai, the screen is showing the name of the second source. example: Comic Sans MS = comic.ttf.

1 answer

1


I stopped Delphi a long time ago, I’m a little outdated, but I got this sample code on the Internet and it works. You have to run the application with permissions at the administrator level:

procedure TForm1.ListBox1Click(Sender: TObject);
var
  Regkey : TRegistry;
begin
  Regkey := TRegistry.Create;
  Regkey.RootKey := HKEY_LOCAL_MACHINE;
  Regkey.OpenKey('Software\Microsoft\Windows NT\CurrentVersion\Fonts', true);

  if (Regkey.ValueExists(Listbox1.Items[ListBox1.ItemIndex] + ' (TrueType)')) then begin
    ShowMessage(Regkey.ReadString(Listbox1.Items[ListBox1.ItemIndex] + ' (TrueType)'));
  end else begin
    ShowMessage('Font file name not found');
  end;

  Regkey.CloseKey;
end;

I suppose from there you can continue the project, but any doubt just talk.

  • After you put this one to work, you can also get the . otf fonts by changing the "(Truetype)" of the record to "(Opentype)". Clear this path in the regedit you will see there more clearly.

  • Thank you, that’s exactly what I was looking for, God bless!

  • @Edsoncosta, since my answer helped you solve your problem, so if you have no further questions, could you please accept it? If there is still any doubt or point to clarify, please tell me so that we can clarify it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.