Recent

Author Topic: How To Write A Lazarus Component  (Read 833 times)

Aruna

  • Full Member
  • ***
  • Posts: 119
How To Write A Lazarus Component
« on: December 03, 2022, 06:28:10 am »
Hello everyone, I came across this article on How to write a Lazarus component? I was wondering if it is possible to do this through code.
Can we write a Lazarus component using nothing but pascal code?

Does anyone have a simple beginners example of code that shows how to do this?

I was thinking if I use the code below as a boiler-plate and write it out to a disk file that should work yes? Or am I insane?

Code: Pascal  [Select][+][-]
  1. unit CustomControl1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.   TCustomControl1 = class(TComboBox)
  12.   private
  13.     { Private declarations }
  14.   protected
  15.     { Protected declarations }
  16.   public
  17.     { Public declarations }
  18.   published
  19.     { Published declarations }
  20.   end;
  21.  
  22. procedure Register;
  23.  
  24. implementation
  25.  
  26. procedure Register;
  27. begin
  28.   RegisterComponents('Standard', [TCustomControl1]);
  29. end;
  30.  
  31. end.

Thank you.

Aruna
« Last Edit: December 03, 2022, 06:43:00 am by Aruna »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4459
  • I like bugs.
Re: How To Write A Lazarus Component
« Reply #1 on: December 03, 2022, 09:27:53 am »
Can we write a Lazarus component using nothing but pascal code?
Well, all Lazarus components are written using Pascal code. There are plenty of examples in various component packages, and in LCL.
Your boiler-plate was created by the "New Component" wizard and is a good start.

Quote
Or am I insane?
Maybe all component creators are insane, I don't know...
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

wp

  • Hero Member
  • *****
  • Posts: 11858
Re: How To Write A Lazarus Component
« Reply #2 on: December 03, 2022, 01:40:47 pm »
Does anyone have a simple beginners example of code that shows how to do this?
The wiki article that you mentioned is the "technical" part of the job, i.e. how to integrate the code into the IDE so that the user can work with it easily. The more difficult part is to write the component code itself. I think the best way to learn this is by looking at examples. Simple components are TChemText (package laz_chemtext), TCaptchaLabel (package captcha_pkg), several components in the industrial package etc.

Aruna

  • Full Member
  • ***
  • Posts: 119
Re: How To Write A Lazarus Component
« Reply #3 on: December 03, 2022, 05:15:26 pm »
Can we write a Lazarus component using nothing but pascal code?
Well, all Lazarus components are written using Pascal code. There are plenty of examples in various component packages, and in LCL.
Your boiler-plate was created by the "New Component" wizard and is a good start.
Ok, so this is good. I am on the correct path.

Maybe all component creators are insane, I don't know...
haha well.. they say "genius borders on insanity" but I would not know either :-)

Aruna

  • Full Member
  • ***
  • Posts: 119
Re: How To Write A Lazarus Component
« Reply #4 on: December 03, 2022, 05:17:39 pm »
Does anyone have a simple beginners example of code that shows how to do this?
The wiki article that you mentioned is the "technical" part of the job, i.e. how to integrate the code into the IDE so that the user can work with it easily. The more difficult part is to write the component code itself. I think the best way to learn this is by looking at examples. Simple components are TChemText (package laz_chemtext), TCaptchaLabel (package captcha_pkg), several components in the industrial package etc.
Thank you, now why did 'I' never think of that? Of course, go study the code in actual components others have written. 

 

TinyPortal © 2005-2018