TRect event within a class lazarus / 31-LCL ---------------------------------------------------------------------- nikel · 2021-10-15 19:09 Hello, I'm trying to create a slider class. The code below works fine on main form but while running it within the class I'm getting error: Identifier not found "OnPaint"; 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 Procedure TSlideBox.DoRun;Begin  TRect.Create(FBackRect, True);   With FBackRect Do  Begin    Left:=8;    Top:=152;    Width:=618;    OnPaint:=@BackRectOnPaint;  End;End; How can I set onpaint event within a class? ---------------------------------------------------------------------- jamie · 2021-10-15 19:54 It has to be parented. You need to provide a way to set the parent of your class which you know should be a TFORM for example. And in that routine.. TForm(Parent).OnPaint := ..... Is that what you were looking for ? ---------------------------------------------------------------------- howardpc · 2021-10-15 20:00 If TSlideBox is designed to be an independent control which can paint itself it must descend from TGraphicControl or TCustomControl, which both provide a Paint method and an OnPaint property. All descendants of TCustomControl (such as TScrollBox and TForm) and all descendants of TGraphicControl (such as TShape) then inherit an OnPaint property which you can call. Currently it looks as though TSlideBox has a different ancestry. ---------------------------------------------------------------------- nikel · 2021-10-15 20:49 I'm new to oop, the class is defined as: 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  PSlideBox = ^TSlideBox;   { TSlideBox }   TSlideBox = Class  Private  FName         : String;... When I run TSlideBox = Class(TForm1) I'm getting errors. Thank you for your replies. ---------------------------------------------------------------------- howardpc · 2021-10-15 21:27 You can tryCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ... Controls, ... ; type TSlideBox = class(TCustomControl)private   FName: String;...end;However, if this is your first go at designing a new component, you may need a bit more help than this. Not sure why you would ever need the PSlideBox type. ---------------------------------------------------------------------- nikel · 2021-10-15 22:06 I'm trying to create a TrackBar with two sliders. ---------------------------------------------------------------------- ASerge · 2021-10-16 06:43 Quote from: nikel on October 15, 2021, 09:09:43 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Procedure TSlideBox.DoRun;Begin  TRect.Create(FBackRect, True);   With FBackRect Do  Begin    Left:=8;    Top:=152;    Width:=618;    OnPaint:=@BackRectOnPaint;  End;End;If your code is really like this, then you can simply delete line 3 - nothing will change. ---------------------------------------------------------------------- bytebites · 2021-10-16 06:56 Like so https://forum.lazarus.freepascal.org/index.php?topic=45063.0 ? ---------------------------------------------------------------------- nikel · 2021-10-16 08:55 Hello, I tried changing class definition to "TSlideBox = Class(TCustomControl)" but this time I got error for the TRect Canvas. I found this at an external site: Quote... forget about OnClick, simply use Click 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 Public  Procedure Click; Override; 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 Procedure TLoginButton.Click;Begin  Inherited; // Call the inherited Click method.  // Do something new.End; ---------------------------------------------------------------------- howardpc · 2021-10-17 15:59 Quote from: nikel on October 16, 2021, 12:06:47 amI'm trying to create a TrackBar with two sliders. I thought about how I would implement such a thing, and the attached test program and unit might give you some ideas. I implemented mouse and keyboard support (but not design support if you want to turn it into a standalone component). With two sliders there are various behaviours that you can support. In the attached example clicking on the track affects the lower slider if you click to the left of it, and clicking between the sliders causes them to move towards each other. Clicking to the right of the higher slider moves it further right. Keyboard movement with arrow keys affects the lower slider. To move the upper slider, press Ctrl+arrow key. I have not implemented working code for the vertical orientation, but left placeholders you can complete if this is what you need. It is almost untested, and only so far on Linux, so I am sure it has bugs. It is offered as a proof of concept. ---------------------------------------------------------------------- nikel · 2021-10-17 18:30 Thank you for your reply. I tried it and seemed fine. I'd like to use it in my project if you excuse me. ---------------------------------------------------------------------- howardpc · 2021-10-17 18:35 You're welcome. Use it and adapt it as needed.