Forum > Beginners

get the form's name when a procedure is called

(1/3) > >>

Gald:
Hello! I'm looking for the easiest way to get the form's name when a procedure is called without the need to pass it when calling it.
Example:


--- 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";}};} ---// In form 999999procedure TForm999999.Button3Click(Sender: TObject);begin      MyFunction('abc');end; // In Unit Communprocedure MyFunction(aText: String); var aOwner: TWinControl;begin   aOwner: GetFormNameWhoCalledThisProcedure;  //code...end;
Can someone help me?

Bart:
The more obvious solution would be to redeclare the MyFunction as:

--- 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 MyFunction(Sender: TObject; aText: String);var  F: TCustomForm;begin  if Sender is TControl then F := GetParentForm(TControl(Sender))  //code...end;
Bart

lucamar:
A little more complete example:

--- 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";}};} ---// In form 999999procedure TForm999999.Button3Click(Sender: TObject);begin      MyFunction(Self, 'abc');end; // In Unit Communprocedure MyFunction(Sender: TObject; aText: String);var  F: TCustomForm;  FormName: String;begin  if Sender is TControl then begin    F := GetParentForm(TControl(Sender));    FormName := F.Name; { in case you want it for anything else }    ShowMessageFmt('Called with %s from form %s', [aText, FormName]);  end;  { rest of code }end;

Gald:
Thank you both, guys.
But is there some idea of how to do it without the need to pass as a parameter when calling it?

Handoko:
No.

Navigation

[0] Message Index

[#] Next page

Go to full version