Case of with "is" Keyword lazarus / 21-General ---------------------------------------------------------------------- Weitentaaal · 2021-08-17 14:38 Hello is it possible to rewrite this "if" and "else if's" to Case of ?: Current --> 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    for i := 0 to StartUp.ComponentCount - 1 do begin      If StartUp.Components[i] is TLabel then begin         TLabel(StartUp.Components[i]).Font.Height:= 6;      end else if StartUp.Components[i] is TEdit then begin         TEdit(StartUp.Components[i]).Font.Height:= 6;      end else if StartUp.Components[i] is TButton then begin         TButton(StartUp.Components[i]).Font.Height:= 6;      end;   end;  What i thought of --> 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    for i := 0 to StartUp.ComponentCount - 1 do begin      Case StartUp.Components[i] of         is TLabel :  TLabel(StartUp.Components[i]).Font.Height:= 6;         is TEdit:  TEdit(StartUp.Components[i]).Font.Height:= 6;         is TButton:  TButton(StartUp.Components[i]).Font.Height:= 6;      end;   end;  or is there a better Solution to cover all Components of form without writing all down ? (for example for the "OnResize" Function.Like that i would only need 1 for-loop to Resize everything and i would not have to write everything Single handed down) ---------------------------------------------------------------------- wp · 2021-08-17 15:01 Not directly. An indirect version using the classname strings works, but does not handle inheritance: 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  i: Integer;begin  for i := 0 to GroupBox1.ControlCount-1 do    case Uppercase(GroupBox1.Controls[i].ClassName) of      'TEDIT': Memo2.Lines.Add('TEdit');      'TMEMO': Memo2.Lines.Add('TMemo');    end;   // The version utilizing the inheritance of TEdit and TMemo from the same ancestor, TCustomEdit would be  // for i := 0 to GroupBox1.ControlCount-1 do  //    if GroupBox1.Controls[i] is TCustomEdit then ...  // and this would cover both TEdit and TMemo in a single instruction  Returning to your example, you should remember that Font is introduced already in TControl as a public property, so you could simplify your code like that: 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 var  C: TControl;...for i := 0 to StartUp.ComponentCount-1 do begin  if StartUpComponents[i] is TControl then  begin    C := TControl(StartupComponents[i]);    if (C is TLabel) or (C is TEdit) or (C is TButton) then      C.Font.Height := 6;  end;end; And do not confuse Font.Height and Font.Size: Font.Size is the font size given in typographical points, where 1pt is 1/72 inch. Font.Height is the font size given in pixels on the current device and it is usually handled as a negative number. I could imagine, that entering it as a positive value might introduce some trouble here and there. ---------------------------------------------------------------------- Weitentaaal · 2021-08-17 15:08 And do not confuse Font.Height and Font.Size: Font.Size is the font size given in typographical points, where 1pt is 1/72 inch. Font.Height is the font size given in pixels on the current device and it is usually handled as a negative number. I could imagine, that entering it as a positive value might introduce some trouble here and there. Couldn't follow what excactly u mean by "usually handled as a negative number". I will use Size but what could / would happen by using height with positiv Numbers ---------------------------------------------------------------------- MarkMLl · 2021-08-17 15:15 Quote from: Weitentaaal on August 17, 2021, 05:08:00 pmCouldn't follow what excactly u mean by "usually handled as a negative number". I will use Size but what could / would happen by using height with positiv Numbers If I'm reading things correctly assume he meant "usually specified as". MarkMLl ---------------------------------------------------------------------- howardpc · 2021-08-17 15:16 The usually negative value for Font.Size derives from the Microsoft GDI where when the mapping mode is mm_Text (the usual case when dealing with fonts)  the lfHeight field can be either positive or negative. Positive values indicate that the height unit is in points. Negative values indicate that the units are pixels. This is carried over from the Delphi VCL for compatibility reasons. ---------------------------------------------------------------------- wp · 2021-08-17 15:31 Quote from: Weitentaaal on August 17, 2021, 05:08:00 pmwhat could / would happen by using height with positiv Numbers Look at the object inspector for some control. By default Font.Size is 0, so you don't see much difference betwen Font.Size and Font.Height. Set the Font.Size of the form (or some other control) to something like 12. You see in Font.Height the value -16 (assuming that you work on a standard display with 96 pixels per inch). Font.Size 12 means: "12 pt", or the height of a line is 12/72 inch. On the 96ppi display you can replace the "inch" by "96 pixels", and you can calculate the line height to be 12/72*96 = 16 pixels -- exactly what Font.Height tells you, except for the sign. Nothing changes, when you enter the Font.Height as a positive number, i.e. 16 rather than -16 -- except for the Font.Size which is negative now. When you are lucky that's all. But I could imagine that there are some components out there which do not consider the Font.Size to be negative. So some kind of risk... The most important effect of confusing Font.Size and Font.Height is that the "real" font size will be different. Put two TLabels on a form. For the first label, set Font.Size = 12, and for the other one set Font.Height = -12 --> both labels will have different heights (unless you are on a screen with 72 ppi). ---------------------------------------------------------------------- Weitentaaal · 2021-08-18 05:43 Thanks to all 3 of u Guys ---------------------------------------------------------------------- Weitentaaal · 2021-08-18 09:08 Question : Why isn't the following working ? (Wrote this bc if u would change Resolution then my Programm would become useless) 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    IF (Screen.Width <> 1920) or (Screen.Height <> 1080)) then begin      For i := 0 to StartUp.ComponentCount - 1 do begin         If StartUp.Components[i] is TControl then begin            TControl(StartUp.Components[i]).Width:= round(TControl(StartUp.Components[i]).Width * (Screen.Width / 1920));            TControl(StartUp.Components[i]).Height:= round(TControl(StartUp.Components[i]).Height * (Screen.Height / 1080));         end;      end;   end; ---------------------------------------------------------------------- ASerge · 2021-08-19 07:38 I want to remind that each TComponent class has a default enumerator, i.e. 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 var  C: TComponent;begin  for C in StartUp do    if (C is TLabel) or (C is TEdit) or (C is TButton) then      C.Font.Height := 6;end; And if need to list only controls, then the TWinControl class has the GetEnumeratorControls method: 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 var  C: TControl;begin  for C in StartUp.GetEnumeratorControls do    if (C is TLabel) or (C is TEdit) or (C is TButton) then      C.Font.Height := 6;end;