How to create a simple extended component and can change his properties lazarus / 31-LCL ---------------------------------------------------------------------- dcelso · 2013-02-25 08:35 How to create a simple extended component and can change his properties in Objec Inspector? Hello, i'm trying create a custom label with an aditional property. To do it i tryied create a new package, use TLabel as parent, add a publised property property mynewprop : integer read fmynewprop write setmynewprop; creating a private fmynewprop integer atribute, and a private procedure setmynewprop(newval : integer) I compile the package, the Tmylabel appears, but I cant see the new property in object inspector. What I need more? Thanks. ---------------------------------------------------------------------- taazz · 2013-02-25 08:42 nothing. The property should be visible on inspector as long as you have your label selected on the form designer. ---------------------------------------------------------------------- dcelso · 2013-02-27 11:34 Thanks, it work well only with basics types, integer, string, etc. But now I'm trying to do it with a custom class, and I can not select it in object inspector, like tshelllistview do with tshelltreeview, for example. property mynewprop : TMyClass read fmynewprop write setmynewprop; ---------------------------------------------------------------------- Blaazen · 2013-02-27 11:45 Your class must be derived from TComponent TPersistent. Also, you have to call "SetSubComponent(True);" in constructor. Code: [Select]constructor TMainComp.Create(AOwner: TComponent); begin   inherited Create(AOwner);   FSubComp:=TSubComp.Create(self);   with FSubComp do     SetSubComponent(True); end; EDIT: I correct myself. TPersistent is enough (for streaming) ---------------------------------------------------------------------- dcelso · 2013-03-01 07:26 It not compile, sais  wrong number of parameters specified for call create and  identifier fsubcomp not found. I trye with create without parameters to solve the first problem but the second problem continues. My two class to do an example are the nexts: Code: [Select]unit umylabel; {$mode objfpc}{$H+} interface uses   Classes, SysUtils,StdCtrls; type   TMyLabel= class(TLabel)   private     { private declarations }     fmycustomclass: TCustomClass ;   public     { public declarations }   published     property mycustomclass :TCustomClass read fmycustomclass write fmycustomclass;   end; implementation end.    Code: [Select]unit uMyCustomClass; {$mode objfpc}{$H+} interface uses   Classes, SysUtils; type   TCustomClass= class(TPersistent)   private     { private declarations }   public     { public declarations }     constructor Create(AOwner: TComponent);   end; implementation constructor TCustomClass.Create(AOwner: TComponent); begin   inherited Create(AOwner);   FSubComp:=TSubComp.Create(self);   with FSubComp do     SetSubComponent(True); end; end. ---------------------------------------------------------------------- taazz · 2013-03-01 07:59 The TPersistent create constructor does not support the owner construct at all. It is not a component so it can not be used as the owner of a component what is the subcomponent type? Declaring an empty property of type TMylabel inside your TMyLabel class is at least questionable the fact that you do not give it any value leaving it at nil will of course  prevents Object inspector from showing any properties that class might have but you should be able to see the property myLabel on the inspector none the less as long as you have installed it in the IDE. ---------------------------------------------------------------------- dcelso · 2013-03-01 12:54 Thansk for the response, I don't want do it. My example was wrong. I want do the same as tshellistview do with tshelltreeview, where you put a tshelllistview you can indicate in a property what object of tshelltreeview want use in it. I want do the same but Tmylabel and tmycustomclass. ---------------------------------------------------------------------- dcelso · 2013-03-01 12:57 The other thing, is a litle stupid ---------------------------------------------------------------------- Blaazen · 2013-03-01 13:18 @ dcelso Sorry for confusion. I quickly looked to my sources wrote the short snippet above. Subclass definitely can be TPersistentand appears in OI but in my code (TSubClass), I declared my own property Parent and my own constructor Create(AParent: TComponent); The reason is that I needed access to main component from subcomponent. And of course, because TPersistent has no owner, you have to free it manually in destructor of the main class. ---------------------------------------------------------------------- taazz · 2013-03-01 13:19 It is not recomended to use the TPersistent in that way there are a lot of things that it does not support that will bring the ide to its knees as an example TPersistent does not support the free notification mechanism making impossible to know when the external component is destroyed leaving your component in an unstable state. There is also the problem of the property editor that needs to defined or written in order to allow the end user to select only your specific class which of course is unknown to the IDE. If you want to do such an elaborate linking between your component and some other 3rd one, then you need to make sure that both of them are inherited from at least TComponent to make your life easier with the IDE integration. ---------------------------------------------------------------------- dcelso · 2013-03-01 19:38 Thanks. But i dont undertand how chage my ucustomclass to solve it, yet. . I ve deleted the parameter of constructor but it continues doing errors. I ve changed tpersistern to tcomponent with sames results. Deleting constructor. It compiles. But when i install the package and i use my tmylabel i dont see in object inspector the property mycustomclass to select an object.  Like tshelllistview do with tshelltreeview. ---------------------------------------------------------------------- Blaazen · 2013-03-01 20:30 I attached a very simple component LabelX with SubClass(TPersistent) which appears in OI - I tested  . EDIT: Oops, everything works, it appears in OI, I only forgot to free subcomponent. However, it is easy to fix, I will not upload new version. You can: add destructor TLabelX.Destroy and call SubClass.Free there OR change SubClass from TPersistent to TComponent and set owner. Owner will care. ---------------------------------------------------------------------- dcelso · 2013-03-02 12:05 Thanks, I'll study it. But I 've discovered that an application with custom visual components, is more dificult to mantain that other that use the commons lazarus components and adding the needed things manually. Because if you change of computer you need donload lazarus, compile package, install package on ide and recompile it (to can see it on palette and objtect inspector), compile project, then you can start to write code etc. If you use same units in your package and in your project, lazarus does not do to you compile together, it sais that you are using in your project and is not recomended add it to you package, but it does not leave to you do it. And If you have all without packages you only need run lazarus and start to write code . ---------------------------------------------------------------------- Blaazen · 2013-03-02 12:15 QuoteBecause if you change of computer you need donload lazarus, compile package, install package on ide and recompile it (to can see it on palette and objtect inspector), compile project, then you can start to write code etc. If you use same units in your package and in your project, lazarus does not do to you compile together, it sais that you are using in your project and is not recomended add it to you package, but it does not leave to you do it. Hmm, I can imagine that this is problem in school where is many computers and you sit everytime elsewhere. So you need install Laz.+components to every machine. I work with only one PC and recompiling Laz. or adding new component is done in acceptable time. When I do only a small change in component which is already installed, rebuilding IDE is a few seconds. ---------------------------------------------------------------------- dcelso · 2013-03-02 12:34 Quote from: Blaazen on March 02, 2013, 01:15:41 pmQuoteBecause if you change of computer you need donload lazarus, compile package, install package on ide and recompile it (to can see it on palette and objtect inspector), compile project, then you can start to write code etc. If you use same units in your package and in your project, lazarus does not do to you compile together, it sais that you are using in your project and is not recomended add it to you package, but it does not leave to you do it. Hmm, I can imagine that this is problem in school where is many computers and you sit everytime elsewhere. So you need install Laz.+components to every machine. Exactly. . In other hand,  I saw you example, , It's a great example, I love it, I will use this method to another project that I have.I have a question related with it, is it not necessary to create the destructor to free the tsubcomponet? How free it currently. But it is not that Im searching in this thread. I'm searching the interconection of two visual components, like, I insist, tshelllistview do with tshelltreeview. When you Drop a tshelllistview to your form in a property called shelltreeview you can select an object of this tipe, for example you can drop to your project three tshelltreeviews, and in your shelllistview1.shelltreeview property you can see shelltreeview1,shelltreeview2 and shelltreeview3 to select one of this. So the control of create or destroy they have the application, instead of your custom visual component (as your example, tlabelx, do) ---------------------------------------------------------------------- dcelso · 2013-03-03 23:29 Quote from: dcelso on March 02, 2013, 01:34:20 pm.... But it is not that Im searching in this thread. I'm searching the interconection of two visual components, like, I insist, tshelllistview do with tshelltreeview. When you Drop a tshelllistview to your form in a property called shelltreeview you can select an object of this tipe, for example you can drop to your project three tshelltreeviews, and in your shelllistview1.shelltreeview property you can see shelltreeview1,shelltreeview2 and shelltreeview3 to select one of this. ... Anyone knows how to do it? ---------------------------------------------------------------------- Blaazen · 2013-03-03 23:58 I am not sure that I perfectly understand. TShellTreeView is just for browsing files. If you want to browse different paths in one ShellTreeView, you can only change its "root" property. It can be done in many ways. You can use TTabControl, TComboBox, Buttons etc. There's no need to create new component. ---------------------------------------------------------------------- dcelso · 2013-03-04 00:25 Don't tshelllistview have a property called shelltreeview, this property can be changed in object inspector in design time, to select an object of tshelltreeview type. At press in this property in object inspector a combobox open a list of all of yours objects of this type have in your project to selec one. for example if you drop two tshelltreeview from the components palette to your form, you will have two objects of tshelltreeview, shelltreeview1 and shelltreeview2, and those names You will see when you try to change the shelltreeview propertry of your shelllistview1 in the object inspector. This kind of interconection of objects Is that I`m trying to simulate. ---------------------------------------------------------------------- dcelso · 2013-03-06 18:01 , I done it. I'm the best  You only need extend of TComponent your two classes. And register they in the component palette. And automatically you can interconect they as tshellistview and tshelltreeview do. ---------------------------------------------------------------------- dcelso · 2013-03-06 18:29 But now, I don`t do it circular. I have a tmyedit and a tmylabel, and tmyedit have a porperty called mylabel that you can select an object of tmylabel dropped from palette. I'm trying to do now the same in tmylabel,ie, a property called myedit that you can select and object of tmyedit. But when it add umylabel unit lazarus sais that there is a circular reference beteen umyedit an umylabel, and it does not compile. ---------------------------------------------------------------------- JuhaManninen · 2013-03-06 18:42 Quote from: dcelso on March 06, 2013, 07:29:30 pmI'm trying to do now the same in tmylabel,ie, a property called myedit that you can select and object of tmyedit. But when it add umylabel unit lazarus sais that there is a circular reference beteen umyedit an umylabel, and it does not compile. In that case the cross-reference really must be in the interface part. The only solution is to copy the components into one unit. LCL has the same problem with many components. The code is divided into smaller files by using include files for the implementation part. Lazarus IDE fully understands and supports include files. About the original problem: The best way to know how a certain component works, is to look at its source code. This is open source after all. Just Ctrl-Click TShelLlistView or TShellTreeView and you are taken to its sources. Maybe you did just that, I don't know. Juha