[Solved] Passing arguments to custom event lazarus / 21-General ---------------------------------------------------------------------- nikel · 2025-01-05 14:04 Hello, I'm trying to pass arguments for my panel's paint event. Here's my code so far: 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 FPanels[I].OnPaint:=@PanelPaintHandler(nil, 20); // Modify: I changed FMarginX to 20 And my function: 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 TMain_Frm.PanelPaintHandler(Sender: TObject; Margin1: Integer);var  Panel        : TPanel;begin   ...This is giving me error QuoteError: Variable identifier expected How can I pass multiple arguments to custom event? ---------------------------------------------------------------------- Bart · 2025-01-05 14:18 OnPaint is not a custom event. In your example, you can simply access FMarginX in OnPaint, or call PanelPaintHandler from within OnPaint. Bart ---------------------------------------------------------------------- nikel · 2025-01-05 14:22 Thanks for the quick reply. I can't write within OnPaint event because the panels are created programmatically. FMarginX doesn't work as I expected. Here's my code: 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 TMain_Frm.PanelPaintHandler(Sender: TObject);var  Panel        : TPanel;begin  Panel:=TPanel(Sender);   with Panel do  begin    with Canvas do    begin      with Pen do      begin        Color:=clRed;      Width:=3;      end;       Line(FMarginX, 23, FMarginX + 12, 23);  end;  end;   Panel.Refresh;   Panel:=nil;  Panel.Free;end; I guess FMarginX + 12 increments the variable. ---------------------------------------------------------------------- Bart · 2025-01-05 14:52 Quote from: nikel on January 05, 2025, 03:22:39 pmI can't write within OnPaint event because the panels are created programmatically. That makes no sense to me. If you use a TForm's OnPaint: you can traverse all components on the form, so you know if a panel exists or not. If you use the TPanel's OnPaint: you can assign that in code after creating. Bart ---------------------------------------------------------------------- VisualLab · 2025-01-05 15:30 You have something similar given in the example that I attached to my reply in the thread "Line drawn is immediately deleted". I mean connecting one procedure to an event in several objects (in this case TPanel and TRadioButton). In this case it was about the OnPaint event in panels and the OnChange event in radio buttons. The implementation method is similar for other controls and their events, including those that are created programmatically. It might be convenient to place panels in a TObjectList list, which would be set as the owner of the panels being created (e.g. the argument FreeObjects = True in the list constructor). Then deleting the list will automatically delete the panels as well. You should also remember to set the parent of the panels (the Parent property). Parent is not the same as owner (Parent <> Owner). EDIT: I am attaching a small example of dynamically creating panels and attaching event handlers to them. EDIT2: I am attaching a second small example of dynamically creating panels and attaching event handlers to them. ---------------------------------------------------------------------- Remy Lebeau · 2025-01-05 19:56 You can't pass in parameters when ASSIGNING an event, only when CALLING the event. Also, you can't add new parameters that the event type is not expecting. Try something more like this instead: 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 FPanels[I].OnPaint := PanelPaintHandler;FPanels[I].Tag := 20; // FMarginX...procedure TMain_Frm.PanelPaintHandler(Sender: TObject);var  Panel : TPanel;  Margin : Integer;begin  Panel := TPanel(Sender);  Margin := Panel.Tag;  ...end; ---------------------------------------------------------------------- nikel · 2025-01-05 21:55 VisualLab, thanks for the detailed answer. Remy Lebeau, your code works fine.