method declaration with a perdefined value lazarus / 21-General ---------------------------------------------------------------------- Nicole · 2023-07-12 13:28 There is a class with a method. I want to call this class in both ways: by machine call AND on button Click. I thought: If there is a value passed, so all is fine, take it. If there is no value see it by the "-1" (and read if from the form, but this is not our topic) And I wrote: 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 TFrame_bearbeiteDB.SpeedButton_OrderInDB_BClick(id_trade_ :integer = -1); and I though the "-1" would be the value of d_trade onSpeedButton_OrderInDB_BClick I was surprised to see, that the value was not "-1", but "undefined". Question to those, who are not surprised: What is wrong? Thanks PS: The value is a primary key, so it will be a positive integer in the end. ---------------------------------------------------------------------- PascalDragon · 2023-07-12 20:11 Do I understand correctly that SpeedButton_OrderInDB_BClick is assigned to a TSpeedButton's OnClick event handler in the object inspector? If that is so then your signature is wrong. The signature must match the signature of the event handler, cause the LCL will simply call the event handler in the way it expects to call it and if you have a different signature you'll get garbage as input. ---------------------------------------------------------------------- Zvoni · 2023-07-13 06:27 Aircode 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 Order_InDB(id_trade:integer=-1);Begin//Do Something in DBEnd; Procedure SomeForm.SomeButtonClick(Sender:TObject);Begin   //Since no Parameter is given, it "passes" -1 as Value   Order_InDB; //Or is it Order_InDB(); ?End; //Calling from code: Pass 42 as ValueOrder_InDB(42); ---------------------------------------------------------------------- Nicole · 2023-07-13 12:13 Thank you for the answers. Now I am not surprised any more, that this does not work. Yes, it is done by the Object inspector. This was the first part. Next question: Am I obliged to write TSome.ButtClick(Sender: TObject);? or will it work to write TSome.ButtClick; // Lazarus suggests this by a hint, useful or misleading or TSome.ButtClick(Sender: TObject; yeahspeak: string; AndSomeMore: integer=0 );? ---------------------------------------------------------------------- cdbc · 2023-07-13 12:28 Hi As long as your method signature looks like this: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 TSome.ChikaBumBum(Sender: TObject); You can assign it to TNotifyEvent property or callback etc. 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 TNotifyEvent = procedure(Sender: TObject) of object;"of object" means that it has to be a method, not just a procedure, albeit, there are also tricks to get around that hurdle  ...And remember you can put just about anything in a "TObject"  Regards Benny ---------------------------------------------------------------------- Zvoni · 2023-07-13 12:49 Quote from: Nicole on July 13, 2023, 02:13:40 pmNext question: Am I obliged to write TSome.ButtClick(Sender: TObject);?Yes Quoteor will it work to write TSome.ButtClick; // Lazarus suggests this by a hint, useful or misleading or TSome.ButtClick(Sender: TObject; yeahspeak: string; AndSomeMore: integer=0 );? No. As Pascal wrote: The Signature must be exactly as defined for an OnClick-Event IMO, the only way is as i've shown in my Aircode above: Write a separate Procedure (as part of the Form or standalone in the unit, or even a public procedure in some other unit), and delegate From the Click-Event or call it directly from your code ---------------------------------------------------------------------- Bart · 2023-07-13 13:55 Unfortunately the IDE dos not check the method signature of events when loading the lfm. So, in source editor, you can actually change them, only to be later surprised by e.g. nasty faults like acces violations. AFAIK Delphi inform you that the signature is incorrect when you load the project in the IDE. (There is a bugreport about that already.) Bart