Recent

Author Topic: How to hide/show forms without cross-referencing?  (Read 838 times)

C0m3b4ck

  • New Member
  • *
  • Posts: 30
  • Open-source programs for Windows 95-11 and Linux
    • Github
How to hide/show forms without cross-referencing?
« on: March 26, 2026, 05:45:27 pm »
Hello, I recently came over from Visual Basic 6 to Free Pascal. In Visual Basic 6, you have an option to hide forms like this: FormName.Hide. I attempted to replicate that in FP, but needed to include a form's unit in order to hide it. Since my program only has 4 forms, I quickly encountered the problem of cross-referencing and that did not allow me to compile.

My question is: how to call a function that hides a form without cross-referencing? Do I need to do this in main unit? Please preferably give a simple solution but any solution is welcome!

Thank you in advance!  :)
Github profile - https://github.com/C0m3b4ck | YouTube Channel - https://youtube.com/@PrinterFixer
Current Pascal project - https://github.com/C0m3b4ck/BookwormPascal - library book management app

Still making sure I support Win95 for its users out there...

cdbc

  • Hero Member
  • *****
  • Posts: 2816
    • http://www.cdbc.dk
Re: How to hide/show forms without cross-referencing?
« Reply #1 on: March 26, 2026, 07:13:58 pm »
Hi
Well, an example says more than words...
Read the comments in the source...
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

creaothceann

  • Sr. Member
  • ****
  • Posts: 375
Re: How to hide/show forms without cross-referencing?
« Reply #2 on: March 26, 2026, 08:17:58 pm »
I attempted to replicate that in FP, but needed to include a form's unit in order to hide it. Since my program only has 4 forms, I quickly encountered the problem of cross-referencing and that did not allow me to compile

You can include the other unit in the implementation's uses list.

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3.  
  4. interface
  5. uses
  6.         // ...
  7.  
  8.  
  9. implementation
  10. uses
  11.         Unit2, // ...
  12.  
  13.  
  14. procedure Test;
  15. begin
  16.         Form2.Hide;  // Form2 is in Unit2
  17. end;
  18.  
  19.  
  20. end.

C0m3b4ck

  • New Member
  • *
  • Posts: 30
  • Open-source programs for Windows 95-11 and Linux
    • Github
Re: How to hide/show forms without cross-referencing?
« Reply #3 on: March 27, 2026, 05:47:28 am »
Thank you cdbc and creaothceann, I will check it out and if it works and I have no more questions, the form can be closed.
Github profile - https://github.com/C0m3b4ck | YouTube Channel - https://youtube.com/@PrinterFixer
Current Pascal project - https://github.com/C0m3b4ck/BookwormPascal - library book management app

Still making sure I support Win95 for its users out there...

C0m3b4ck

  • New Member
  • *
  • Posts: 30
  • Open-source programs for Windows 95-11 and Linux
    • Github
Re: How to hide/show forms without cross-referencing?
« Reply #4 on: March 28, 2026, 12:47:45 pm »
I decided to use my initial idea with a module called FormManager that stores all of the required functions. Then I added initialization of each form right before "application.run" in my .lfm file. For each form, the initialization would look like this:
Code: Pascal  [Select][+][-]
  1. RegisterForm('formnametobeused', Tform_name)

Each of these forms then use FormManager. Note that the hide function does not work when called from a form to hide itself, so I used Self.Hide in such cases. Files below - check out bookworm.lfm, FormManager.pas for the functions and usage. Feel free to use!
Github profile - https://github.com/C0m3b4ck | YouTube Channel - https://youtube.com/@PrinterFixer
Current Pascal project - https://github.com/C0m3b4ck/BookwormPascal - library book management app

Still making sure I support Win95 for its users out there...

 

TinyPortal © 2005-2018