Lazarus

Programming => General => Topic started by: Weitentaaal on January 25, 2021, 09:51:58 am

Title: Use a reference to The Form as a Procedure Parameter
Post by: Weitentaaal on January 25, 2021, 09:51:58 am
Hello :)

just a Short Question:

is it possible to do this?: 
Code: Pascal  [Select][+][-]
  1.  
  2. Function TGlobals.Calc_STD(var curForm: Form; FeldD: String; ResEurevo: Single): Boolean;
  3.  
  4.  

and in my Function then do something like

Code: Pascal  [Select][+][-]
  1.  
  2. curForm.Name
  3.  
  4.  

Thanks :)
Title: Re: Use a reference to The Form as a Procedure Parameter
Post by: MarkMLl on January 25, 2021, 10:22:14 am
Should be but the type is TForm and don't pass it as var... you aren't going to change it, and an object is implicitly passed by address/reference.

MarkMLl
Title: Re: Use a reference to The Form as a Procedure Parameter
Post by: dbannon on January 25, 2021, 10:36:21 am
Not sure exactly what you are asking here Weitentaaal.  Let me try ..

You want to set a variable to point to a form and do things like call methods in the form from that variable ?  Yeah, no problems.  For example, I have a unit/form called TEditBoxForm.  I make any number of these forms, each one displays a note from a note collection.

Code: Pascal  [Select][+][-]
  1. procedure ShowNote(anEBox : TEditBoxForm);
  2. begin
  3.     anEBox.show;
  4. end;
  5.  
  6. var
  7.     EBox : TEditBoxForm;
  8.     NoteFileName : string;
  9.     TheForm : TForm;
  10. begin    
  11.     EBox := TEditBoxForm.Create(Application);
  12.     EBox.NoteTitle:= NoteTitle;
  13.     EBox.NoteFileName := NoteFileName;
  14.     ShowNote(EBox);    
  15.     ....
  16.  
I might then, save the value of EBox in a list so I can later look through all the open notes, see if user has closed one etc.  I am using, as an example here, a form I create rather than have it created at startup because for what you are asking seems to make more sense with dynamically created forms.

Is this the sort of thing you are after ?

Davo
Title: Re: Use a reference to The Form as a Procedure Parameter
Post by: Weitentaaal on January 25, 2021, 10:41:43 am
Yesss

Was looking For this

Thank u Guys
TinyPortal © 2005-2018