Custom Component Width and Height lazarus / 10-Designer ---------------------------------------------------------------------- Aruna · 2024-08-31 10:57 Hi, I have a custom control that functions as intended. However, when I first click on it in the component panel and then click on the form to place an instance, it initially appears as a small black box (it looks like a dot, but I’m not sure how else to describe it). You can see this issue in the first attached screenshot.. I have explicitly set height and width in the code: 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  FMemo.Width  :=600;   FMemo.Height :=180; Once I manually drag the bottom-right corner of the component to resize it, I can adjust the width and height to my liking, and everything works as expected. You can see this in the second attached screenshot. My question is: How can I ensure that Lazarus uses the width and height specified in my code for the control? For some reason, it t seems like Lazarus either doesn't pick up these dimensions or ignores them. Here is the source: 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 unit Tlsusb; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Controls, StdCtrls, Process; type  { TLSB }  TLSB = class(TCustomControl)  private    FMemo: TMemo;    procedure DoRunCommand;  protected    procedure CreateWnd; override;  public    constructor Create(AOwner: TComponent); override;  published    property Align;    property Anchors;    property Font;    property ParentFont;    property ParentShowHint;    property ShowHint;    property TabOrder;    property TabStop;    property Visible;  end; procedure Register; implementation constructor TLSB.Create(AOwner: TComponent);begin  inherited Create(AOwner);   // Initialize the memo  FMemo        := TMemo.Create(Self);  FMemo.Parent := Self;  FMemo.Align  := alClient;//  FMemo.Width  :=600;//  FMemo.Height :=180;  FMemo.Font.Name:= 'Monospace';  //FMemo.ScrollBars := ssVertical;  // Run the command  DoRunCommand;end; procedure TLSB.CreateWnd;begin  inherited CreateWnd;  // Additional initialization if necessaryend; procedure TLSB.DoRunCommand;var  outstr: string;begin  RunCommand('lsusb', [''], outstr);  FMemo.Lines.Add(outstr);end; procedure Register;begin  RegisterComponents('Linux Sysinfo', [TLSB]);end; end.  Second question is if I change the FMemo.Align  := alClient; to alNone things do not work. 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  FMemo.Align  := alClient; Why is this? And how do I fix? EDIT: Oh btw, is how I have gone about doing this ok? Or there are more elegant ways to do this? If so please do share. Thank you! ---------------------------------------------------------------------- bobby100 · 2024-08-31 11:14 Try to put this into Create 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 with GetControlClassDefaultSize do    SetInitialBounds(0, 0, 50, 50); ---------------------------------------------------------------------- wp · 2024-08-31 11:19 Quote from: Aruna on August 31, 2024, 12:57:29 pmHowever, when I first click on it in the component panel and then click on the form to place an instance, it initially appears as a small black box (it looks like a dot, but I’m not sure how else to describe it). This happens when the component has zero size. You did not specify its Width and Height in the constructor (only those of the FMemo, but this is not relevant for the component. The recommended way how to specify component size in its constructor is by calling the function GetControlClassDefaultSize and passing its return value to SetInitialBounds. Compared to setting Width and Height directly, this avoids a lot of overhead which is unnecessary at this early stage of component creation. 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 TLSB.Create(AOwner: TComponent);begin  inherited Create(AOwner);  with GetControlClassDefaultSize do    SetInitialBounds(0, 0, CX, CY);end; class function TLSB.GetControlClassdefaultSize: TSize;  // must be declared in protected and as "override"begin  Result.CX := 100;     // This is the initial size of the component TLSB. Please adapt as needed.  Result.CY := 100;end; Having set the control's size should fix also the issue with FMemo.Align. ---------------------------------------------------------------------- Aruna · 2024-08-31 12:45 Quote from: bobby100 on August 31, 2024, 01:14:29 pmTry to put this into Create 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 with GetControlClassDefaultSize do    SetInitialBounds(0, 0, 50, 50);Perfect! Thank you. ---------------------------------------------------------------------- Aruna · 2024-08-31 12:51 Quote from: wp on August 31, 2024, 01:19:10 pmQuote from: Aruna on August 31, 2024, 12:57:29 pmHowever, when I first click on it in the component panel and then click on the form to place an instance, it initially appears as a small black box (it looks like a dot, but I’m not sure how else to describe it). This happens when the component has zero size. You did not specify its Width and Height in the constructor (only those of the FMemo, but this is not relevant for the component. The recommended way how to specify component size in its constructor is by calling the function GetControlClassDefaultSize and passing its return value to SetInitialBounds. Compared to setting Width and Height directly, this avoids a lot of overhead which is unnecessary at this early stage of component creation. 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 TLSB.Create(AOwner: TComponent);begin  inherited Create(AOwner);  with GetControlClassDefaultSize do    SetInitialBounds(0, 0, CX, CY);end; class function TLSB.GetControlClassdefaultSize: TSize;  // must be declared in protected and as "override"begin  Result.CX := 100;     // This is the initial size of the component TLSB. Please adapt as needed.  Result.CY := 100;end; Having set the control's size should fix also the issue with FMemo.Align. @wp thank you for the guidance I now have a fair understanding of how things work. I have another question for you, if I may. In Linux 'lsblk' we have multiple switches one can use: 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 lsblk -alsblk -Slsblk- Jlsblk -t how would I go about incorporating this into my component? I was thinking RadioGroup but cannot quite wrap my head around this. What I want is to give the user the ability to choose what they want lsblk to do. Or should I open a new thread? ---------------------------------------------------------------------- TRon · 2024-08-31 13:01 Quote from: Aruna on August 31, 2024, 02:51:08 pmIn Linux 'lsblk' we have multiple switches one can use: 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 lsblk -alsblk -Slsblk- Jlsblk -t how would I go about incorporating this into my component? I was thinking RadioGroup but cannot quite wrap my head around this. What I want is to give the user the ability to choose what they want lsblk to do. Or should I open a new thread? If requiring detailed instructions then usually a new thread is preferred. I don't believe a radiogroup supports nested buttons. e.g. some of these options are optional or working in conjunction with. the -J is one such option, it is the output format which can be turned on for every other request. To my knowledge that should at least become something like a radiogroup /and/ (on or more) checkboxes. I am not aware of a component that combines that functionality (or could easily be produced) but also realize that my knowledge regarding (3th party) components is not that extensive. ---------------------------------------------------------------------- Aruna · 2024-08-31 13:07 Quote from: TRon on August 31, 2024, 03:01:31 pmQuote from: Aruna on August 31, 2024, 02:51:08 pmIn Linux 'lsblk' we have multiple switches one can use: 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 lsblk -alsblk -Slsblk- Jlsblk -t how would I go about incorporating this into my component? I was thinking RadioGroup but cannot quite wrap my head around this. What I want is to give the user the ability to choose what they want lsblk to do. Or should I open a new thread? If requiring detailed instructions then usually a new thread is preferred. I don't believe a radiogroup supports nested buttons. e.g. some of these options are optional or working in conjunction with. the -J is one such option, it is the output format which can be turned on for every other request. To my knowledge that should at least become something like a radiogroup /and/ (on or more) checkboxes. I am not aware of a component that combines that functionality (or could easily be produced) but also realize that my knowledge regarding (3th party) components is not that extensive. Understood and thanks. I will start a new thread as I am learning and detailed instructions would be nice:-) @TRon am not trying to plug in buttons. I have the component working right? Thanks to you showing me how to use RunCommand() some time back. So, I was thinking what if I have a group of radio buttons and when the user selects one then run the corresponding lsblk switch? No buttons are involved. ---------------------------------------------------------------------- TRon · 2024-08-31 13:13 Quote from: Aruna on August 31, 2024, 03:07:36 pmSo, I was thinking what if I have a group of radio buttons and when the user selects one then run the corresponding lsblk switch? No buttons are involved. That should work, no doubt. See for example the compiler commands that the Lazarus IDE passes through to the compiler for inspiration: https://wiki.lazarus.freepasc al.org/IDE_Window:_Compiler_Options#Adding_a_release_and_debug_build_m odes ---------------------------------------------------------------------- wp · 2024-08-31 15:33 Adding a radiogroup to the component reduces its flexibility. Maybe some time in the future your form has little space and it would be better to have a combobox? Rather than adding a control I would define an "Options" property. Then the user can decide on his own how to switch between the options. In order to define such a property declare 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 type  TLSBOption = (lsboA, lsboS, lsboJ, lsboT); type  TLSB = class(TCustomControl)  private    FOption: TLSBOption;    procedure DoRunCommand;   public    constructor Create(AOwner: TComponent);    procedure RunCommand;  published  // to have it in the ObjectInspector. Or only public?    property Option: TLSBOption read FOption write FOption;  end; constructor TLSB.Create(AOwner: TComponent);begin  inherited Create(AOwner);  FOption := lsboJ;   // Set the default option  // Do not call DoRunCommand hereend; procedure TLSB.RunCommand;begin  DoRunCommand;end; procedure TLSB.DoRunCommand;const  optionStr: array[TLSBOption] of string = ('-a', '-S', '-J', '-t');var  outstr: string;begin  Process.RunCommand('lsusb', [optionStr[FOption]], outstr);  FMemo.Lines.Add(outstr);end; ---------------------------------------------------------------------- Aruna · 2024-09-01 00:54 Quote from: wp on August 31, 2024, 05:33:50 pmAdding a radiogroup to the component reduces its flexibility. Maybe some time in the future your form has little space and it would be better to have a combobox?Ah.. I did not think of this. Yes, very true. Quote from: wp on August 31, 2024, 05:33:50 pmRather than adding a control I would define an "Options" property. Then the user can decide on his own how to switch between the options.@wp yes certainly I will try this. My concern is with a property that is effective only at design time? I am not dead sure about this but this is what I have seen so far. I set the property and compile things work fine. Great! Now if I set the property again to something else and click the button in the running application and nothing is picked up about the change in properties. I want to be able to select any option at run-time. Not have to stop the running program then change the property then recompile and run. Quote from: wp on August 31, 2024, 05:33:50 pmIn order to define such a property declare 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 type  TLSBOption = (lsboA, lsboS, lsboJ, lsboT); type  TLSB = class(TCustomControl)  private    FOption: TLSBOption;    procedure DoRunCommand;   public    constructor Create(AOwner: TComponent);    procedure RunCommand;  published  // to have it in the ObjectInspector. Or only public?    property Option: TLSBOption read FOption write FOption;  end; constructor TLSB.Create(AOwner: TComponent);begin  inherited Create(AOwner);  FOption := lsboJ;   // Set the default option  // Do not call DoRunCommand hereend; procedure TLSB.RunCommand;begin  DoRunCommand;end; procedure TLSB.DoRunCommand;const  optionStr: array[TLSBOption] of string = ('-a', '-S', '-J', '-t');var  outstr: string;begin  Process.RunCommand('lsusb', [optionStr[FOption]], outstr);  FMemo.Lines.Add(outstr);end; Thank you so much @wp I will give this a go. Why have you said 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 // Do not call DoRunCommand here ---------------------------------------------------------------------- Aruna · 2024-09-01 01:39 Hi, I have attached what I have managed to come up with so far. It does work ( but not the way I would like it to :-) I have learned a lot and I am thankful. If I want to set the background color of the Tmemo using a property how does one do that?