Forum > General

[ SOLVED ] Frame and procedure

(1/2) > >>

superc:
Hello,

I've a Form with 4 TTabShett , in one of these there are loaded at runtime a TTframe;
now I need to call a procedure of the parent form from the frame for refresh components into frame.
I created a procedure in the Frame can accept tobject, and I pass parent form and inside the frame I cast and call the procedure, but is a good methods?

Thanks in advance.

mas steindorff:
I use the following code a lot, not just for Frames, but also in my classes so they can talk back to their owner only if the owner is able to handle the info.  if the owner does not "register" then the info is just ignored.

in your frame code...

--- 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";}};} ---type   TShowStatusEvent   = procedure(str:string) of object; // to pass strings back =>GUI // then in the type section of your  tFrame... "TmyFrame" in this example private   fOnShowStatus :TShowStatusEvent;  //    ...public    property OnShowStatus :TShowStatusEvent   read FOnShowStatus     Write FOnShowStatus; ...end;  
and later...

--- 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 TmyFrame.PassStr(Str);begin  if assigned(FOnShowStatus) then    begin      FOnShowStatus(str);    end;end;  then your frame code will pass this stuff on to the procedure (if any) that has been "registered ". in the owners code, perhaps in the create ...

--- 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";}};} --- // myFrame := TmyFrame.create(myPanel4frame); // only needed if you create at runtime ... myFrame.OnShowStatus := @myRevieverOfStrings; // where myRevieverOfStrings is ...procedure Tform.myRevieverOfStrings(str:string)begin // do something with string or ignore itend; 
"string" can be replaced with a variable or a even a record.  I tend to make separate call backs for status info and for debug info for more complexes classes.

if ignoring is not acceptable, you can get aggressive and showmessage(info) or add a visual indicator on your frame.
 

MAS

moessner:
I wish thank a lot.

moessner - mario piva

superc:

--- Quote from: mas steindorff on April 20, 2022, 06:51:48 pm ---I use the following code a lot, not just for Frames, but also in my classes so they can talk back to their owner only if the owner is able to handle the info.  if the owner does not "register" then the info is just ignored.

in your frame code...

--- 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";}};} ---type   TShowStatusEvent   = procedure(str:string) of object; // to pass strings back =>GUI // then in the type section of your  tFrame... private   fOnShowStatus :TShowStatusEvent;  //    ...public    property OnShowStatus :TShowStatusEvent   read FOnShowStatus     Write FOnShowStatus; ...end;  
and later...

--- 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 TThreadComm.PassStr(Str);begin  if assigned(FOnShowStatus) then    begin      FOnShowStatus(str);    end;end;  then your frame code will pass this stuff on to the procedure (if any) that has been "registered ". in the owners code, perhaps in the create ...

--- 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";}};} --- myFrame.OnShowStatus := @myRevieverOfStrings; // where myRevieverOfStrings is ...procedure Tform.myRevieverOfStrings(str:string)begin // do something with string or ignore itend; 
"string" can be replaced with a variable or a even a record.  I tend to make separate call backs for status info and for debug info for more complexes classes.

if ignoring is not acceptable, you can get aggressive and showmessage(info) or add a visual indicator on your frame.
 

MAS

--- End quote ---

Thank you for ther reply, I think it is a very elegant method, now I'm try to implement it  :D

superc:
Well, I'm implemented similar code to my program and works well, except the part:



--- 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 TThreadComm.PassStr(Str);begin  if assigned(FOnShowStatus) then    begin      FOnShowStatus(str);    end;end;  
I don't understand where to insert this piece of code, why should i use assigned?

Thanks in advance.


Navigation

[0] Message Index

[#] Next page

Go to full version