Forum > General

Send a control name to a function or procedure

(1/2) > >>

andyf97:

I want to pass the name of the component to a function or procedure that will eventually run a popup menu related to that component, having trouble sending the name of the control and I get an error.

I suppose that I should convert the TObject name to a string somehow.

unit1.pas(130,22) Error: Incompatible type for arg no. 1: Got "AnsiString", expected "TObject"



--- 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";}};} ---  // this is just a little procedure to see the name passes, just for testing I want the name to go to the caption of form1procedure TForm1.SliderRightClick(sender: TObject);begin  Form1.caption := '';end;  // this is the right click popup event of the control.procedure TForm1.ECSlider1ContextPopup(Sender: TObject; MousePos: TPoint;  var Handled: Boolean); Var this:string; begin  this:=TComponent(sender).name;// This does contain the control name ECSlider1   SliderRightClick(this);// How can I send the name stored in the variable this to the procedure TForm1.SliderRightClick end;                         

KodeZwerg:
What is wrong by using sender as argument?

andyf97:

Not sure what you mean.

I have a load of these sliders and want to just copy a bit of duplicated code into each ones popup event and not need make them all specific when the names are already specific.




--- Quote from: KodeZwerg on March 29, 2023, 10:09:39 pm ---What is wrong by using sender as argument?

--- End quote ---



KodeZwerg:

--- 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";}};} ---SliderRightClick(Sender);And do the rest in your SliderRightClick method.

andyf97:
I do not have a rightclick events, I have a ContextPopup that all appears fine. I just dont get how to pass the name of it, to a function or procedure event tho I can put the name into a variable. But after writing I realized what you meant.

Yes that works but then I get another error got a Tobject but expected a Ttranslatesting.


--- Quote from: KodeZwerg on March 29, 2023, 10:19:45 pm ---
--- 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";}};} ---SliderRightClick(Sender);And do the rest in your SliderRightClick method.

--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version