Forum > Beginners

Setting events stored in other unit to controls

(1/4) > >>

Gald:
Hello hello!

I trying to do something like this:


--- 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";}};} ---Label1.OnClick:=@LabelClick;
But the event LabelClick is on another unit.
None of this below is working.


--- 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";}};} ---Label1.OnClick:=@Unit2.LabelClick;Label1.OnClick:=Unit2.@LabelClick;Label1.OnClick:=Unit2.SomeClass.LabelClick;Label1.OnClick:=Unit2.SomeClass.@LabelClick;Label1.OnClick:=@Unit2.SomeClass.LabelClick;
Then, how can I do it?

Bart:
Define "not working".
Compilation error?
Runtime error?
Something else?

Bart

Gald:

--- Quote from: Bart on May 09, 2021, 07:25:15 pm ---Define "not working".

--- End quote ---

C:\Test\unit1.pas(37,20) Error: (4001) Incompatible types: got "<address of procedure(TObject);Register>" expected "<procedure variable type of procedure(TObject) of object;Register>"

There's also this hit info on Attachment.

jamie:
seems to work for me.

--- 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";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin  Onclick := unit2.form2.Onclick;end;                                                  
You need to define from an instance of the class, not the class itself.

Gald:
Could you please look at this sample project?
I still having problems.

Navigation

[0] Message Index

[#] Next page

Go to full version