GetPropValue and TFont lazarus / 21-General ---------------------------------------------------------------------- domasz · 2022-03-31 12:25 How can I use GetPropValue or similar function to get TFont.Name? something like: Code: [Select]Font := GetPropValue(Button1, 'Font') as TFont; ShowMessage(Font.Name); ---------------------------------------------------------------------- howardpc · 2022-03-31 13:07 Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses Graphics; var  fontName: String;begin  fontName := GetFontData(Button1.Font.Handle).Name;...end; ---------------------------------------------------------------------- domasz · 2022-03-31 14:14 Thank you, but my control is TControl. If it were TButton or something known (TCombobox, TEditbox...) then I could just do Button1.Font.Name. ---------------------------------------------------------------------- Zvoni · 2022-03-31 14:58 Then you're probably out of luck: https://www.freepascal.org/docs- html/rtl/typinfo/getpropvalue.html QuoteDue to missing Variant support, GetPropValue is not yet implemented. The declaration is provided for compatibility with Delphi. Looking at the Source in typinfo.pp around line 2900, in the end it relays to an OnGetPropValue-Function, which is set to Nil (around Line 910) ---------------------------------------------------------------------- wp · 2022-03-31 15:04 Quote from: domasz on March 31, 2022, 04:14:34 pmThank you, but my control is TControl. If it were TButton or something known (TCombobox, TEditbox...) then I could just do Button1.Font.Name. In Lazarus, Font is a public property of TControl (unlike in Delphi), and therefore you can always access Control.Font. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  C: TControl;begin  C := Button1;  ShowMessage(C.Font.Name);end; ---------------------------------------------------------------------- domasz · 2022-03-31 17:00 Quote from: wp on March 31, 2022, 05:04:57 pmIn Lazarus, Font is a public property of TControl (unlike in Delphi), and therefore you can always access Control.Font. Holy crap! It's that easy! Thank you so much! I really like Lazarus more and more after so many Delphi years (since Delphi 4 or 5) . ---------------------------------------------------------------------- howardpc · 2022-03-31 19:48 Quote from: domasz on March 31, 2022, 04:14:34 pmThank you, but my control is TControl. If it were TButton or something known (TCombobox, TEditbox...) then I could just do Button1.Font.Name. The reason I suggested Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i GetFontData(Button1.Font.Handle).Name;rather than the obviousCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Button1.Font.Nameis that often the latter simply returns "default" which I presumed is not what you are after. ---------------------------------------------------------------------- wp · 2022-03-31 19:55 Quote from: howardpc on March 31, 2022, 09:48:57 pmQuote from: domasz on March 31, 2022, 04:14:34 pmThank you, but my control is TControl. If it were TButton or something known (TCombobox, TEditbox...) then I could just do Button1.Font.Name. The reason I suggestedCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i GetFontData(Button1.Font.Handle).Name;rather than the obvious GetFontData() is important to retrieve the true font name and height, in particular when a font is named "default" and has Size zero which are the LCL's font default settings. ---------------------------------------------------------------------- PascalDragon · 2022-04-01 13:33 Quote from: Zvoni on March 31, 2022, 04:58:47 pmThen you're probably out of luck: https://www.freepascal.org/docs- html/rtl/typinfo/getpropvalue.html QuoteDue to missing Variant support, GetPropValue is not yet implemented. The declaration is provided for compatibility with Delphi. Looking at the Source in typinfo.pp around line 2900, in the end it relays to an OnGetPropValue-Function, which is set to Nil (around Line 910) The documentation should probably be updated (please file a bug report): OnGetPropValue and OnSetPropValue are hooked when the Variants unit is included, because using the TypInfo unit should not imply that the whole Variant handling is linked in as well. Though in my opinion one should use the correct getter if one already knows the type of the property. In this case this would be GetObjectProp. ---------------------------------------------------------------------- domasz · 2022-04-02 12:08 Quote from: howardpc on March 31, 2022, 09:48:57 pmThe reason I suggested Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i GetFontData(Button1.Font.Handle).Name;rather than the obviousCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Button1.Font.Nameis that often the latter simply returns "default" which I presumed is not what you are after. Thank you, this is useful! ---------------------------------------------------------------------- Zvoni · 2022-04-04 06:48 Quote from: PascalDragon on April 01, 2022, 03:33:53 pmThe documentation should probably be updated (please file a bug report): OnGetPropValue and OnSetPropValue are hooked when the Variants unit is included, because using the TypInfo unit should not imply that the whole Variant handling is linked in as well. Though in my opinion one should use the correct getter if one already knows the type of the property. In this case this would be GetObjectProp. https://gitlab.com/freepascal.org/fpc/source/-/issues/39647 ---------------------------------------------------------------------- PascalDragon · 2022-04-04 11:26 Quote from: Zvoni on April 04, 2022, 08:48:04 amhttps://gitlab.com/freepascal.org/fpc/source/-/issues/39647 Thank you.