Recent

Author Topic: Using multiple forms  (Read 30683 times)

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Using multiple forms
« Reply #15 on: September 02, 2017, 06:39:44 am »
Carefully at second form "Form2" not same the first form.

Yes, i know that  :)

That is why i wrote "..waiting to happen".

When you have a couple of forms in your project, let's say 25 then do you know from memory which forms used another form inside the interface uses clause ?

I guess not, because you start adding other units in the interface section to access other forms and 'out of the blue' you have yourself a circular unit reference, which you would then have to solve.

Note that this can happen indirectly as well, so you're basically lost after 4 levels of depth and 4 or 5 forms trying to access other forms (and none of those accessing another form directly).
« Last Edit: September 02, 2017, 06:55:03 am by molly »

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Using multiple forms
« Reply #16 on: September 02, 2017, 06:40:56 am »
Case 3 multi form or more.

At the head of Form1:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
  Classes, SysUtils, Forms, Controls, ...,  unit2, unit3;
Please just stop advertising bad coding habits   >:D

There is no use at all to do that in the interface section, at least not with the code you showed so far.

Carefully read my previous reply and check it yourself and be amazed at how unhelpful the compiler can be in such cases.
« Last Edit: September 02, 2017, 06:58:53 am by molly »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Using multiple forms
« Reply #17 on: September 02, 2017, 01:12:20 pm »
Carefully at second form "Form2" not same the first form.

Yes, i know that  :)

That is why i wrote "..waiting to happen".

When you have a couple of forms in your project, let's say 25 then do you know from memory which forms used another form inside the interface uses clause ?

Yes, the mainform uses all the forms that needs, the rest 24, use none.

I guess not, because you start adding other units in the interface section to access other forms and 'out of the blue' you have yourself a circular unit reference, which you would then have to solve.

Note that this can happen indirectly as well, so you're basically lost after 4 levels of depth and 4 or 5 forms trying to access other forms (and none of those accessing another form directly).
Nope there is only one level of depth and proper coding. If for any reason I fill the need to use any other form then I know my design is wrong.

When you write code you must think each unit as an island, it can fire a flare (event and event lists), to inform the islands interested in its affairs that something changed, but it can never reach out and touch other islands with out starting a war.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

Lulu

  • Full Member
  • ***
  • Posts: 230
Re: Using multiple forms
« Reply #18 on: September 02, 2017, 08:58:50 pm »
I read the whole of this subject, it is very interesting, and I learned again today! thank you to all of you !  :)
wishing you a nice life

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Using multiple forms
« Reply #19 on: September 03, 2017, 04:28:08 am »
Yes, the mainform uses all the forms that needs, the rest 24, use none.
So you implement all your programs in such simplistic design and every form is only invoked from the main form (and main form only) ?

That is perfectly ok if that works for your clients/programs.

Quote
Nope there is only one level of depth and proper coding. If for any reason I fill the need to use any other form then I know my design is wrong.
I'm perfectly ok with the fact that you seem to want to imply that there is something wrong with my design skills, but such remark (icw the one above) seems to suggest to me that there is missing something from yours. No offense.

Quote
When you write code you must think each unit as an island, it can fire a flare (event and event lists), to inform the islands interested in its affairs that something changed, but it can never reach out and touch other islands with out starting a war.
Indeed an island. Self contained and which can be invoked from everywhere in the application at any time (when required).

So in order to avoid (future) problems it is much better to avoid including other units inside the interface section of a unit (i have marked the exceptions to that rule).

In case you wanted to get your point across that DavidTh30's example works as intended then i guess you have made your point. But that point only works in practice for that particular example of simplistic (linear) design.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Using multiple forms
« Reply #20 on: September 03, 2017, 04:47:05 am »
Yes, the mainform uses all the forms that needs, the rest 24, use none.
So you implement all your programs in such simplistic design and every form is only invoked from the main form (and main form only) ?
No every form can be invoked from anywhere in my application it just does not need to know that the action taken will show a form or not.


That is perfectly ok if that works for your clients/programs.

Yeah I would like to see you try that simplistic design and see how easy it is to accomplish.

Quote
Nope there is only one level of depth and proper coding. If for any reason I fill the need to use any other form then I know my design is wrong.
I'm perfectly ok with the fact that you seem to want to imply that there is something wrong with my design skills, but such remark (icw the one above) seems to suggest to me that there is missing something from yours. No offense.
No at all, I can not comment on your design with out knowing your specification and use cases I'm talking about my designs and my designs along, and a simplistic rule that needs to be enforced in all of them.
Quote
When you write code you must think each unit as an island, it can fire a flare (event and event lists), to inform the islands interested in its affairs that something changed, but it can never reach out and touch other islands with out starting a war.
Indeed an island. Self contained and which can be invoked from everywhere in the application at any time (when required).
True.
So in order to avoid (future) problems it is much better to avoid including other units inside the interface section of a unit (i have marked the exceptions to that rule).

In case you wanted to get your point across that DavidTh30's example works as intended then i guess you have made your point. But that point only works in practice for that particular example of simplistic (linear) design.
No I'm just sharing my experience and "rule of contact" nothing more nothing less fill free to ignore me. I always do.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Using multiple forms
« Reply #21 on: September 03, 2017, 09:45:01 am »
No every form can be invoked from anywhere in my application it just does not need to know that the action taken will show a form or not.
Nor does any form unit need to be included. Sorry but i don't see your point in the context of the thread.

Quote
Yeah I would like to see you try that simplistic design and see how easy it is to accomplish
No idea what makes you think i haven't done so already. The original question was not about different design implementations nor were these expressed (until you mentioned it ofc).

Quote
...and a simplistic rule that needs to be enforced in all of them.
And in real life that simply isn't always possible nor desired.

Quote
... fill free to ignore me. I always do.
I value your opinion but so far you haven't been able to convince me at all that i should start adding form-units into my interface section (or implementation section for that matter).

alaa123456789

  • Sr. Member
  • ****
  • Posts: 260
  • Try your Best to learn & help others
    • youtube:
Re: Using multiple forms
« Reply #22 on: December 22, 2020, 05:10:37 pm »

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
Re: RE: Using multiple forms
« Reply #23 on: January 04, 2021, 12:15:09 am »
You can not start early enough getting used to using try .. except or try .. finally.

I wish there was a video tutorial for this! :D :D
Free Pascal Lazarus Version #: 2.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

cdbc

  • Hero Member
  • *****
  • Posts: 1083
    • http://www.cdbc.dk
Re: Using multiple forms
« Reply #24 on: January 04, 2021, 04:25:03 pm »
Hi
I'm with matthijs on this one!
You can even make a class function on the form, to do the work...
Just a thought  :)
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

 

TinyPortal © 2005-2018