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:
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:
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 necessary
end;
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.
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!