Passing a Frame as a component property lazarus / 31-LCL ---------------------------------------------------------------------- pcurtis · 2022-03-06 14:13 Hi there. This question comes in two parts. 1. How can I pass a TFrame (from a pas file) into a TCustomControl? 2. Once I have this property in the component how can I use this to typecast? For example - 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 (Something as TFrame1).DoProcedure.  Where TFrame1 is the property of the TcustomControl? Hope it's understandable. ---------------------------------------------------------------------- egsuh · 2022-03-07 02:05 Frankly speaking, I don't understand what you want to do. TFrame is a descendant of TCustomControl, so you should be able to pass any TFrame to TCustomControl variable, as following. But not sure whether this is what you are thinking.  var     ACC: TCustomControl; begin    ACC:=  TFrame1.Create(nil);     (ACC as TFrame1).AnyOfTFrame1Properties := ... ---------------------------------------------------------------------- Martin_fr · 2022-03-07 04:44 Quote from: pcurtis on March 06, 2022, 03:13:15 pm1. How can I pass a TFrame (from a pas file) into a TCustomControl? 2. Once I have this property in the component how can I use this to typecast? For example - 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 (Something as TFrame1).DoProcedure.  Where TFrame1 is the property of the TcustomControl? Hope it's understandable. Do you mean something like 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 TheClassOfSomeFrame: ????;begin  (Something as TheClassOfSomeFrame).DoProcedure; Or maybe instead of "var TheClassOfSomeFrame" => have "property TheClassOfSomeFrame: ??? read ...." ? So basically at some point before that code you would have assigned 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 TheClassOfSomeFrame := TMyFrame;? I don't think you can do that. You can have 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 TFrameClass = class of TFrame;var TheClassOfSomeFrame: TFrameClass;begin  TheClassOfSomeFrame := TMyDescendendOfTFrame; But, you can not use this for typecasting. Well not the way you apparently try to do. Those variables work for calling virtual constructors. Or virtual class-methods. Anything where the class itself becomes an argument. The do not actually typecast. The do not give access to any methods that are not also in the base-class. They do not type-cast. ---------------------------------------------------------------------- pcurtis · 2022-03-07 05:31 OK, thanks guys. At least a reaction So for the second question. How can I create the variable from the file? I have two files (the frame, MyFrame.pas and MyFrame.lfm), how do I create a var from this ACC:=  TFrame1.Create(FrimFiles); ---------------------------------------------------------------------- egsuh · 2022-03-07 06:28 QuoteI have two files (the frame, MyFrame.pas and MyFrame.lfm), how do I create a var from this Add myframe to uses clause of calling unit^^. uses     Forms, ...  , MyFrame; var     ACC: TCustomControl; begin    ACC:=  TFrame1.Create(nil);    (ACC as TFrame1).AnyOfTFrame1Properties := ... ---------------------------------------------------------------------- pcurtis · 2022-03-07 06:57 That is what I would normally do but I have a problem. I have a project and component that use the same Frame files. When I am designing and make changes to the frame and then try to compile the IDE complains that the file in the frame files in the project and component are different and bombs out. So my idea is to dynamically load the frame files into component. ---------------------------------------------------------------------- egsuh · 2022-03-07 07:12 Please add some snippet codes --- I cannot figure out what you are doing, especially with components. ---------------------------------------------------------------------- pcurtis · 2022-03-07 07:42 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 MyPageControl; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, ExtCtrls,  StdCtrls, attabs, ComCtrls, MyFrame;  //<-- I'm trying to get rid of this dependency                                                         // it contains a type TFrame1.                                                      //i would like to load it dynamically type   TMyPageControl= class(TCustomControl)  private    fEnabled: Boolean;  fTabBar: TATTabs;  protected    procedure Paint; override;    procedure EnabledChanged; override;    procedure ShowTab(aTab: Integer);  public    SelectedTab: Integer;    constructor Create(AOwner: TComponent); override;    destructor Destroy; override;    procedure AddTab(aCaption: String);    procedure DeleteTab(aTab: Integer);    procedure TabChanged(Sender: TObject);  procedure TabClick(Sender: TObject);  published    property Align;    property BorderSpacing;    property Enabled;    property Color;    property TabBar: TATTabs read fTabBar write fTabBar;  end; procedure Register; {$R mypagecontrol.res} implementation constructor TMyPageControl.Create(AOwner: TComponent);begin  inherited Create(AOwner);   Enabled:= True;  fEnabled:= Enabled;   if (AOwner as TControl).Color = clDefault then    Color:= clBtnFace  else    Color:= (AOwner as TControl).Color;   fTabBar:= TATTabs.Create(Self);    with fTabBar do      begin        Parent:= Self;        Align:= alTop;      SetSubComponent(True);        Name:= 'TabBar';        OnTabClick:= @TabClick;        OnTabChanged:= @TabChanged;      end;   ControlStyle:= ControlStyle + [csOpaque, csReplicatable, csSetCaption, csAcceptsControls];   SetInitialBounds(0, 0, 240, 160);end; destructor TMyPageControl.Destroy;var  iTemp: Integer;begin  for iTemp:= 0 to fTabBar.TabCount - 1 do    begin      (fTabBar.GetTabData(iTemp).TabObject as TFrame1).Free;    end;  inherited Destroy;end; procedure TMyPageControl.ShowTab(aTab: Integer);var  iTemp: Integer;begin  for iTemp:= 0 to fTabBar.TabCount - 1 do    begin      (fTabBar.GetTabData(iTemp).TabObject as TFrame1).Hide;    end;  (fTabBar.GetTabData(aTab).TabObject as TFrame1).Show;  Invalidate;end; procedure TMyPageControl.TabChanged(Sender: TObject);var  iTemp: Integer;begin  iTemp:= (Sender as TATTabs).TabIndex;  //ShowMessage('Changed ' + iTemp.ToString);end; procedure TMyPageControl.TabClick(Sender: TObject);var  iTemp: Integer;begin  iTemp:= (Sender as TATTabs).TabIndex;  SelectedTab:= iTemp;  ShowTab(iTemp);end; procedure TMyPageControl.DeleteTab(aTab: Integer);begin  if fTabBar.TabCount = 0 then    exit;  (fTabBar.GetTabData(aTab).TabObject as TFrame1).Free;  fTabBar.DeleteTab(aTab, True, False);end; procedure TMyPageControl.AddTab(aCaption: String);var  iTemp: Integer;begin  iTemp:= fTabBar.TabCount;  fTabBar.AddTab(iTemp, aCaption);  fTabBar.GetTabData(iTemp).TabObject := TFrame1.Create(Self);   with (fTabBar.GetTabData(iTemp).TabObject as TFrame1) do    begin      Parent:= Self;      Align:= alClient;      Name:= 'TheFrame' + GetTickCount.ToString;    end;   fTabBar.TabIndex:= fTabBar.TabCount - 1;   ShowTab(fTabBar.TabCount - 1);end; procedure TMyPageControl.EnabledChanged;var  iTemp: Integer;begin  inherited;  fEnabled:= Enabled;  if ControlCount > 0 then  for iTemp:= 0 to ControlCount - 1 do    Controls[iTemp].Enabled:= fEnabled;  Invalidate;end; procedure TMyPageControl.Paint;var  sTemp: String;begin  inherited Paint;   Canvas.Clear;   if fEnabled and Parent.Enabled then    begin      Canvas.Pen.Color := clBlack;    end  else    begin      Canvas.Pen.Color := cl3DShadow;      Canvas.Font.Color := cl3DShadow;    end;   Canvas.MoveTo(0, 0);  Canvas.LineTo(Width - 1, 0);  Canvas.LineTo(Width - 1, Height - 1);  Canvas.LineTo(0, Height - 1);  Canvas.LineTo(0, 0);end; procedure Register; begin  RegisterComponents('Misc',[TMyPageControl]);end; end. ---------------------------------------------------------------------- egsuh · 2022-03-07 08:24 Now I see what you are trying to do. I haven't done much with components and do not know the answer. I believe you already know these. Still, limited to my knowledge, there would be no problem if you do not "register" TMyPageControl. And I'm wondering what will happen if you use MyFrame in the implementation part, not interface section. Sorry for not of help. ---------------------------------------------------------------------- pcurtis · 2022-03-07 08:31 OK, no problem. At least you tried. ---------------------------------------------------------------------- JuhaManninen · 2022-03-07 09:37 Quote from: pcurtis on March 07, 2022, 07:57:09 amI have a project and component that use the same Frame files. If the Frame is in the same component package, any project should also be able to use it. ---------------------------------------------------------------------- howardpc · 2022-03-07 09:42 The attached project uses a frame adapted from your .zip with your custom My... components and third-party controls replaced by standard LCL controls. ---------------------------------------------------------------------- pcurtis · 2022-03-07 10:09 Thanks howardpc. After a brief look, it looks OK. I will look deeper into it later. At the moment I have worked around the issue by not making it a designtime component, but creating it at runtime. It would still be nice to componentize the class. So I will look at it. Thanks.