Recent

Author Topic: Use a reference to The Form as a Procedure Parameter  (Read 229 times)

Weitentaaal

  • Full Member
  • ***
  • Posts: 172
Use a reference to The Form as a Procedure Parameter
« 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 :)
Lazarus: 2.0.6 x86_64-win64-win32/win64
FPC-Version: 3.0.4
Compiler Version: 3.2.0

MarkMLl

  • Hero Member
  • *****
  • Posts: 2541
Re: Use a reference to The Form as a Procedure Parameter
« Reply #1 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
Turbo Pascal v1 on CCP/M-86, multitasking with LAN and graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

dbannon

  • Hero Member
  • *****
  • Posts: 1374
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Use a reference to The Form as a Procedure Parameter
« Reply #2 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
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

Weitentaaal

  • Full Member
  • ***
  • Posts: 172
Re: Use a reference to The Form as a Procedure Parameter
« Reply #3 on: January 25, 2021, 10:41:43 am »
Yesss

Was looking For this

Thank u Guys
Lazarus: 2.0.6 x86_64-win64-win32/win64
FPC-Version: 3.0.4
Compiler Version: 3.2.0

 

TinyPortal © 2005-2018