Forum > LCL

How To Write A Lazarus Component

(1/1)

Aruna:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit CustomControl1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls; type  TCustomControl1 = class(TComboBox)  private    { Private declarations }  protected    { Protected declarations }  public    { Public declarations }  published    { Published declarations }  end; procedure Register; implementation procedure Register;begin  RegisterComponents('Standard', [TCustomControl1]);end; end.
Thank you.

Aruna

JuhaManninen:

--- Quote from: Aruna on December 03, 2022, 06:28:10 am ---Can we write a Lazarus component using nothing but pascal code?

--- End quote ---
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?

--- End quote ---
Maybe all component creators are insane, I don't know...

wp:

--- Quote from: Aruna on December 03, 2022, 06:28:10 am ---Does anyone have a simple beginners example of code that shows how to do this?

--- End quote ---
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:

--- Quote from: JuhaManninen on December 03, 2022, 09:27:53 am ---
--- Quote from: Aruna on December 03, 2022, 06:28:10 am ---Can we write a Lazarus component using nothing but pascal code?

--- End quote ---
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.

--- End quote ---
Ok, so this is good. I am on the correct path.


--- Quote from: JuhaManninen on December 03, 2022, 09:27:53 am ---Maybe all component creators are insane, I don't know...

--- End quote ---
haha well.. they say "genius borders on insanity" but I would not know either :-)

Aruna:

--- Quote from: wp on December 03, 2022, 01:40:47 pm ---
--- Quote from: Aruna on December 03, 2022, 06:28:10 am ---Does anyone have a simple beginners example of code that shows how to do this?

--- End quote ---
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.

--- End quote ---
Thank you, now why did 'I' never think of that? Of course, go study the code in actual components others have written. 

Navigation

[0] Message Index

Go to full version