implications of being stupid in creating a new lazarus component... lazarus / 31-LCL ---------------------------------------------------------------------- Blue1987 · 2011-06-21 10:15 I was trying to start with "creating a new component"  and tried to follow these instructions... http://wiki.lazarus.freepascal.org/How_To_Write_Lazarus_Component I go step by step, but I suddenly stop at this point... (maybe because english is not my native language) QuoteIf you do not see your new component in the component palette, it is most likely that you are not running the re-compiled version of Lazarus. You can set where Lazarus builds to in: Environment -> Environment options -> Files -> Lazarus directory. Instead of calling lazarus directly, you also can use startlazarus, which starts the newly created lazarus, for example the lazarus executable in the ~/.lazarus directory, if you don't have write access to the directory lazarus was installed into. yes, I do not see the new component in the component palette, hence I am not running the re-compiled version of Lazarus... and so what???  What exactly do I have to do??? after "installing" I do not find any "re-compiled" lazarus.exe on my pc, and also if I start "startlazarus.exe" I do not see the new component in the palette... I feel a bit stupid, since I stop just before the wiki- congratulations-line QuoteCongratulations: You have just installed your first package with your first package component. ---------------------------------------------------------------------- Martin_fr · 2011-06-21 12:27 You can always "force" the ide to rebuild, via the "tools" menu. There is an entry "build lazarus" The first step is to make sure, it actually attempts to include your package, with the new component. To verify this: Put a syntax error in your code. The compilation process should stop at the error line. If not, open the package, and repeat the steps for "installation" If the error is detected, remove the error, and compile via the "tools" menu. It should automatically restart at the end. You can disable the automatic restart in the "configure build lazarus" entry of the menu. Then you can check for a new lazarus..exe. (windows lazarus.new.exe ; linux: ~/.lazarus/lazarus ) Of course it is possible that your package is installed, but that your component is not correctly registered. Check your "procedure Register", add some message dialog there, to check it is executed. ---------------------------------------------------------------------- eny · 2011-06-21 20:29 It also depends on the OS. I have built an IDE new project wizard that compiles and installs correctly. However I must first delete the compiled units, then rebuild Lazarus so the package is recompiled during the Lazarus build process. On Linux (Ubuntu) I have to repeat these steps a couple of times and eventually it installs. ---------------------------------------------------------------------- Blue1987 · 2011-06-27 21:56 thank you guys... I managed to create a component... now the problem is how to write the component I need I must admit http://wiki.lazarus.freepascal.org/How_To_Write_Lazarus_Component doesn't help me much I thought it would be enough to copy a component (say the TLabel) and then modify it as I need... is everything I need in StdCtrls.pp ??? is there some "how to" that explains how to create a component (in every step, and makes some examples)?? ---------------------------------------------------------------------- typo · 2011-06-27 22:01 I would recommend you to port some component of Delphi, if any. Then you can learn about component creation and about porting from Delphi. There are conventions that you must follow. ---------------------------------------------------------------------- Blue1987 · 2011-06-27 22:22 Quote from: typo on June 28, 2011, 12:01:26 amI would recommend you to port some component of Delphi, if any. Then you can learn about component creation and about porting from Delphi. There are conventions that you must follow. where do I find Delphi components? (I do not have Delphi on my pc... I am a beginner, and I am starting programming with lazarus). wouldn't it be better to modify a lazarus-native component? p.s. for me that has started as a hobby, and now it is becoming something more like a passion... but I never studied programming or informatics in my life (neither I think I'll have time to attend any course in this topics)... hence I really need some help!! ---------------------------------------------------------------------- typo · 2011-06-27 22:29 If you have good knowledge about multi platform programming, of course modifying a native Lazarus component would be better. This is not your case. Porting a Delphi component would give you a chance to learn from examples. You can find Delphi components here: http://www.torry.net/ or here: http://delphi.icm.edu.pl/ ---------------------------------------------------------------------- Blue1987 · 2011-06-27 22:34 Quote from: typo on June 28, 2011, 12:29:37 amIf you have good knowledge about multi platform programming, of course modifying a native Lazarus component would be better. This is not your case. Porting a Delphi component would give you a chance to learn from examples. You can find Delphi components here: http://www.torry.net/ or here: http://delphi.icm.edu.pl/ thank you so much! now that's time to learn something new ---------------------------------------------------------------------- typo · 2011-06-27 22:54 Anyway, you can always subclass a component inside your program. For example, this implements a custom Paint procedure to a TLabel: Code: [Select]type   TMyLabel = class(TLabel)     public       procedure Paint; override;   end; {...} implementation {...} procedure TMyLabel.Paint; begin   // your code to implement Paint, for example   Canvas.TextOut(0,0,Caption); end;    Now you can create a MyLabel inside your program, at run time, with that overridden Paint procedure instead of the standard one. ---------------------------------------------------------------------- lainz · 2011-06-27 23:33 Quote from: typo on June 28, 2011, 12:54:02 amAnyway, you can always subclass a component inside your program. For example, this implements a custom Paint procedure to a TLabel: Code: [Select]type   TMyLabel = class(TLabel)     public       procedure Paint; override;   end; {...} implementation {...} procedure TMyLabel.Paint; begin   // your code to implement Paint, for example   Canvas.TextOut(0,0,Caption); end;    Now you can create a MyLabel inside your program, at run time, with that overridden Paint procedure instead of the standard one. That's nice. I've added this to the article: http://wiki.lazarus.freepascal.org/How_To_Write_Lazarus_Component#Usin g_custom_paint_procedure ---------------------------------------------------------------------- typo · 2011-06-27 23:56 For most components, and for most methods, it would be recommendable to call inherited procedure iniside it: Code: [Select]procedure TMyLabel.Paint; begin   inherited Paint;   /////////////////////   // your code to implement Paint, for example   Canvas.TextOut(0,0,Caption); end; but inherited behavior is not desirable in this case, since the second writing action would overlap the first (inherited) one.. ---------------------------------------------------------------------- lainz · 2011-06-28 00:25 Quote from: typo on June 28, 2011, 01:56:57 amFor most components, and for most methods, it would be recommendable to call inherited procedure iniside it: Code: [Select]procedure TMyLabel.Paint; begin   inherited Paint;   /////////////////////   // your code to implement Paint, for example   Canvas.TextOut(0,0,Caption); end; but inherited behavior is not desirable in this case, since the second writing action would overlap the first (inherited) one.. Added too. The article was written using lazarus 0.9.25. I've updated the first part of article and also added new pictures. Still not updated at all, and I won't update =D