I.T. Discussion Community!
-Collapse +Expand
Delphi
Search Delphi Group:

Advanced
-Collapse +Expand Delphi To/From
To/FromCODEGuides
-Collapse +Expand Delphi Store
PRESTWOODSTORE

Prestwood eMagazine

June Edition
Subscribe now! It's Free!
Enter your email:

   ► MB LobbyPascal and Delphi Coding BoardDelphi Object PASCAL Topic   Print This     

Questions, questions

Questions, questions in Delphi Object PASCAL topic (part of our Pascal and Delphi Coding group).

Quick Search: Questions   questions   Questions questions  
rt
Castel, -- UK
Which takes precedence - the section in the project file where it gives a list of forms to be automatically created at startup or my choice of form creation via the project option selection bit? Think!

The majority of examples in the online help use "Free" in some context when closing forms, yet hidden away in the depths of the very same online help it also says to use "Release" in preference to "Free" when closing forms as it allows for all actions to finsh before closing. I doubt if I will ever find that particular bit again, but does some clever type know the reasoning\answer? Think!

Thats enough of that. Ed.

 Posted 18 years ago (Thread Starter)
Comment Quote
About rt -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About rt

I do like my jazz and blues!


Post ID #8075, 15 replies
Thread Started 10/28/2002 3:13:00 AM
View Counter=2195
Last Reply Posted 10/31/2002 12:54:00 PM)
Location=Castel, -- UK 
Joined=20 years ago   MB Posts=687   KB Comments=1  
rt
Castel, -- UK
Thank you both, I would like to clarify a couple of things.

I have an application which has only the 'mainform' listed as auto-create in the project options interface, but all the other forms are listed in the application.CreateForm section of the project .dpr file - so just which forms are going to be auto-created? From the answers given I think it looks like all the forms listed in the project file. If this is the case how do I stop this happening, with lots of "//'s" ?!? Coffee!!!!!

In respect of Free and Release then should I be using Release for all my forms?
It also seems strange that the majority of the examples use Free and not Release. And, what does "ca" mean? And then, what is the difference between caFree and Free?
Can\could you offer simple generic type of Release code?

One answer raises another [Sigh] and is again something that is left unexplained. Taken from Marco Canto's books, what is the difference between (self) and (application) as in this code -

From D2 Book - Modal:=TModalForm.Create(Self);
From D6 Book - Modal:=TModalForm.Create(Application);

Thanks.

Thats enough of that. Ed.

 Posted 18 years ago (Thread Starter)
Comment Quote
About rt -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About rt

I do like my jazz and blues!


Post ID #8089 (Level 1.1)  Reply to 8075
Thread Started 10/28/2002 11:22:00 AM
View Counter=2
Location=Castel, -- UK 
Joined=20 years ago   MB Posts=687   KB Comments=1  
rt
Castel, -- UK
I think you ought to do book, or at least as you suggest yourself, a few Knowledge Base articles...

But before you do Roll Eyes could you confirm that in the general run of things and good practice I have interpretted your pearls of wisdom correctly in that I should be using Application in preference to Self and likewise Release in place of Free ?

More question will follow I am sure.. Worried

Thats enough of that. Ed.

 Posted 18 years ago (Thread Starter)
Comment Quote
About rt -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About rt

I do like my jazz and blues!


Post ID #8107 (Level 1.2)  Reply to 8075
Reply Posted 10/29/2002 12:00:00 PM
Location=Castel, -- UK 
Joined=20 years ago   MB Posts=687   KB Comments=1  
rt
Castel, -- UK
>>I'm surprised that nobody caught my error in the post above. In my comment, I said that Sender was TForm1's handle.<<

Ah yes, I was of course waiting to see if you would correct yourself Big Grin!

In the meantime have been pondering why pearls should be so useful Confused in that not only do we have 'pearls of wisdom' but we also have 'pearls before swine'. May be one would keep ones pearls in the silk puse made from the said sows ear on ones said swine Roll Eyes Yes, well.

But to more serious matters, I am afraid I am going to put you on the spot Eek! in that your bit of very practical form opening type code is just the sort of thing us struggling Delphi types need to see.. I could probably think of half a metric dozen instances where a practical piece of code (to accomplish what is basicaly a standard type of task) would save a lot of time and make the application more robust. That would then liberate time to devote to the application itself and save re-inventing the wheel.

To illustrate the point in my earlier post above I raised the question of coding differences between two books by the same author and which to use. As you know every book tells a different story and eventually one begins to think well just what do I do? Which is the reason I started this topic in the first place.

So what about doing a SCC (Swirley Coding Convention Soap Box ) if I come upwith a (very) few ideas?

Thats enough of that. Ed.

 Posted 18 years ago (Thread Starter)
Comment Quote
About rt -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About rt

I do like my jazz and blues!


Post ID #8116 (Level 1.3)  Reply to 8075
Reply Posted 10/30/2002 11:21:00 AM
Location=Castel, -- UK 
Joined=20 years ago   MB Posts=687   KB Comments=1  
rt
Castel, -- UK
RTFM Confused This must be a Colonialism, can you expand, cleanly ..

Well it looks as though we've all got something out of this Big Grin! as you and Rick are delving into the bowels of Delphi, whilst I am more than delighted with the exception error free results of changing Free to Release Now that

I will away to compose the next query. Think!

Thats enough of that. Ed.

 Posted 18 years ago (Thread Starter)
Comment Quote
About rt -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
About rt

I do like my jazz and blues!


Post ID #8129 (Level 1.4)  Reply to 8075
Reply Posted 10/31/2002 7:02:00 AM
Location=Castel, -- UK 
Joined=20 years ago   MB Posts=687   KB Comments=1  
Rick Carter
Cincinnati OH USA
(1) My understanding is that what really counts is what's in the .dpr file, and I believe the "Project Options" dialog is an interface that will make the necessary modifications to that file.
(2) Far as I know "free" is fine, and I'm guessing this may be someplace where the help documentation is either outdated or misleading. But I don't know that for sure. If I wanted to get a definitive answer, I'd see whether the topic is discussed in Ray Lischner's "Secrets" and/or "Hidden Paths" books, and/or search through archives of the Borland ObjectPascal forum and see what the "heavy hitters" like Ray Lischner and Peter Below have had to say about it.
Rick Carter
Chair, Delphi/Paradox SIG
Cincinnati PC Users Group
 Posted 18 years ago
Comment Quote
About Rick Carter -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8081 (Level 1.5)  Reply to 8075
Reply Posted 10/28/2002 7:31:00 AM
Location=Cincinnati OH USA  
Joined=19 years ago   MB Posts=518  
Rick Carter
Cincinnati OH USA
Apparently Scott and I were both composing our answers at the same time, and I'll endorse Scott's answers as more thorough than my own. I might have been content to leave the thread alone if I had seen Scott's answer previously.
Rick Carter
Chair, Delphi/Paradox SIG
Cincinnati PC Users Group
 Posted 18 years ago
Comment Quote
About Rick Carter -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8082 (Level 1.6)  Reply to 8075
Reply Posted 10/28/2002 7:38:00 AM
Location=Cincinnati OH USA  
Joined=19 years ago   MB Posts=518  
Rick Carter
Cincinnati OH USA

The value of Self in this case would also be questionable. Is it the handle of the TForm? Or, since TButton is a descendant of TComponent (and therefore, could possibly be an owner to a collection of component objects), is the value of Self the TButton's handle?

Scott, unless I'm missing something, I think it's pretty clear that, since ClickTheMagicButton is defined as a method of TForm1, the form would be "self." Wouldn't it?
Rick Carter
Chair, Delphi/Paradox SIG
Cincinnati PC Users Group
 Posted 18 years ago
Comment Quote
About Rick Carter -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8118 (Level 1.7)  Reply to 8075
Reply Posted 10/30/2002 12:28:00 PM
Location=Cincinnati OH USA  
Joined=19 years ago   MB Posts=518  
Most Recent Post
Rick Carter
Cincinnati OH USA
While Scott's off preparing his example, I suppose I can at least tell you what "RTFM" stands for. Though I think it's been used some on your side of the pond as well; IIRC, there was (and may still be) a domain name called rtfm.ik.ac.uk

Since the early days of Usenet, people saved typing and bandwidth by using acronyms -- IIRC for "if I recall correctly," as I used above; AFAIK for "as far as I know," etc.

When someone asked a question he should have been able to look up for himself, some rather crude individuals have been known to reply with "RTFM," short for "Read the f***ing manual!"

Well, you asked!
Rick Carter
Chair, Delphi/Paradox SIG
Cincinnati PC Users Group
 Posted 18 years ago
Comment Quote
About Rick Carter -Collapse +Expand
Visit Profile
Approved member.
Member subscribes to this thread with a verified email.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8136 (Level 1.8)  Reply to 8075
Reply Posted 10/31/2002 12:54:00 PM
Location=Cincinnati OH USA  
Joined=19 years ago   MB Posts=518  
Scott Wehrly
Prestwood IT
 (Inactive)
Las Vegas, NV USA
Answers, answers, answers... Now that



Delphi takes the first form in the project file that is allocated with the Application.CreateForm method, and that is the form that is activated in the Application.Run call. Notice that if you don't have any forms in the Auto-create list, there are no Application.CreateForm calls. If you just add an Application.CreateForm method to the project source, you will see the change get applied on the Project/Options tab. They are not mutually exclusive - one list affects the other.



Of course, this doesn't prevent you from writing code to create and run forms before the first Auto-create form. I have to do this all of the time to create splash screens. The trick is to not use Application.CreateForm, but just to use a normal form create call like:

FormSplash := TFormSplash.Create(Application);


Form creations like this can be called before the first Application.CreateForm, and won't appear in the Auto-create list.



But beware! If you add another form to the Auto-create list, or change the Startup form, Delphi will move those lines right after the Application.Initialize call. So, once you get the form flow working properly in your project file, document the flow in a comment block - because Delphi could wind up rearranging your working code.



As for the difference between Free and Release, the former is a TObject method, and the latter a TCustomForm method.



Release is preferred because a Form is used as a container of other WinControl objects (the Form is itself a descendant of TWinControl). In cleanup, it is important to make sure that the proper cleanup methods are called on any contained controls. By comparison, Free just knows about TObject instances, and isn't coded to clean up TWinControl objects.
 Posted 18 years ago
Comment Quote
About Scott Wehrly -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8080 (Level 1.9)  Reply to 8075
Reply Posted 10/28/2002 7:20:00 AM
Location=Las Vegas, NV USA 
Joined=18 years ago   MB Posts=442   KB Posts=19  
Scott Wehrly
Prestwood IT
 (Inactive)
Las Vegas, NV USA
Coffee!!!!! Coffee!!!!! I was just fast on the draw... Yikes!
 Posted 18 years ago
Comment Quote
About Scott Wehrly -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8085 (Level 1.10)  Reply to 8075
Reply Posted 10/28/2002 9:03:00 AM
Location=Las Vegas, NV USA 
Joined=18 years ago   MB Posts=442   KB Posts=19  
Scott Wehrly
Prestwood IT
 (Inactive)
Las Vegas, NV USA
Foot in Mouth Oops! It sounds like the bridge between Project/Options and the Application.CreateForm calls in the dpr file isn't as I said it would be. Foot in Mouth



Well, that being the case, then can we assume that you create the forms as needed in other parts of your code (i.e. all forms other than MainForm do not need to be auto-created)?



If that is true, then just delete (or comment out) the Application.CreateForm calls in the dpr.



As for caFree, that is an action setting to assign to the Forms OnClose event. It's not a method. It's used during the OnClose event for those times when you are testing some condition in code, and you find a reason to prompt the user and not allow the form to close (and you would assign the action of caNone). The VCL reference has a better explanation.



Finally, the Application argument is the global TComponent variable that holds the Windows handle to the application instance. Self is just an object pointer to the current form in scope (which, coincidentally, in the dpr file, is the application instance). Why is it better to use the Application argument than the Self argument? I should create a Prestwood Knowledge Base article about this... Geek Alert!



Here's the short answer. The handle you pass to the Create method is "who's going to be the owner of this new Windows object". The Application handle always remains constant at runtime, but Self changes with every Form. The critical issue is "who's going to call the cleanup on this new Windows object". If you pass "Self" while creating a form from another form, you have to free the new form before your "owning" form closes, otherwise you could cause a memory leak or an access violation.



If the Application handle is used, then that new form is added to the main executable's "bucket o' objects", and the global Application.Terminate (which is implicitely called when the executable terminates) will catch the cleanup if you didn't catch it in code.



Rick, correct me if I'm wrong here... Boxed In
 Posted 18 years ago
Comment Quote
About Scott Wehrly -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8104 (Level 1.11)  Reply to 8075
Reply Posted 10/29/2002 7:23:00 AM
Location=Las Vegas, NV USA 
Joined=18 years ago   MB Posts=442   KB Posts=19  
Scott Wehrly
Prestwood IT
 (Inactive)
Las Vegas, NV USA
Think! Think! Think! <-- closest thing to "pearls of wisdom". We need a graemlin for those...



Yes, and yes.



And, as another pearl, here is the standard format I use for all forms created as-needed (like from button click events or menu selections):

procedure TForm1.ClickTheMagicButton(Sender : TObject);
begin
  FormMagicTrick := TFormMagicTrick.Create(Application);

      // Sender would also work as the parameter here - since it's value is TForm1's handle
  try
    FormMagicTrick.DoSomethingMagic := True;
    FormMagicTrick.ShowModal;
  finally
    FormMagicTrick.Release;
  end;
end;
 Posted 18 years ago
Comment Quote
About Scott Wehrly -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8108 (Level 1.12)  Reply to 8075
Reply Posted 10/29/2002 2:46:00 PM
Location=Las Vegas, NV USA 
Joined=18 years ago   MB Posts=442   KB Posts=19  
Scott Wehrly
Prestwood IT
 (Inactive)
Las Vegas, NV USA
Foot in Mouth erp! Foot in Mouth

I'm surprised that nobody caught my error in the post above. In my comment, I said that Sender was TForm1's handle.

Incorrect. In this method, Sender would be the object pointer handle of the TButton!

The value of Self in this case would also be questionable. Is it the handle of the TForm? Or, since TButton is a descendant of TComponent (and therefore, could possibly be an owner to a collection of component objects), is the value of Self the TButton's handle? Geek Alert!

I think I just found a convincing argument for using Application as the parameter to a TForm.Create method... My Two Cents
 Posted 18 years ago
Comment Quote
About Scott Wehrly -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8111 (Level 1.13)  Reply to 8075
Reply Posted 10/30/2002 6:32:00 AM
Location=Las Vegas, NV USA 
Joined=18 years ago   MB Posts=442   KB Posts=19  
Scott Wehrly
Prestwood IT
 (Inactive)
Las Vegas, NV USA
Warning...major Geek Alert! Geek Alert! Geek Alert! coming...

Well, Rick, you're right. The event method is a member of the TForm1 class. However, according to the old Windows SDK Programming book I have, when an event is dispatched, Windows includes the handle of the object that dispatched the event. That would be the TButton.

The TButton is defined in the published section of the TForm1 class, so it too is a member of the class. Yes, you would think that all objects on a form would use the form's handle for the event dispatch, but then the event manager would break down if that happened. In actuality, since the TButton is also a descendant of TControl, its handle is used when the event is dispatched.

Here's a simple test to illustrate the point. Put this method on a form:

procedure TForm1.ClickByAnybody(Sender :TObject);
begin
  if (Sender is TButton) then
    ShowMessage('Button!')
  else if (Sender is TLabel) then
    ShowMessage('Label!')
  else if (Sender is TPanel) then
    ShowMessage('Panel!')
  else
    ShowMessage('I am something else.');
end;


Then add a TPanel, TButton, and TLabel to the form, and assign each control this method for their OnClick event. Run the form. You'll see what I'm talking about...

Geek Alert! alert over.

As for rt, I would love to get the opportunity to write a book. Big Grin! I'm undoubtedly being conceited here, but I fancy myself as a very good writer.

BTW - swirley is something that no-neck jocks do to Geek Alert! types in high school W.C.'s here (also known as a porcelain shampoo), so I wouldn't include that expression in a title.

I could include your contributions as "R.T.'s formatting methods", or R.T.F.M. for short. Oh, wait. RTFM is already being used for something else... Big Grin!
 Posted 18 years ago
Comment Quote
About Scott Wehrly -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8120 (Level 1.14)  Reply to 8075
Reply Posted 10/30/2002 1:26:00 PM
Location=Las Vegas, NV USA 
Joined=18 years ago   MB Posts=442   KB Posts=19  
Scott Wehrly
Prestwood IT
 (Inactive)
Las Vegas, NV USA
Foot in Mouth Argggh! Foot in Mouth again!

I click the "Add Reply" button too fast. My code is related to Sender, not Self.

Sorry, Rick. I really didn't answer your question correctly.

I guess I'll have to build a little demo and compare the object addresses in the TForm's Component array with the value of Self, and find out for myself. Stay tuned. Coffee!!!!!
 Posted 18 years ago
Comment Quote
About Scott Wehrly -Collapse +Expand
Visit Profile
Inactive member.
Member does not subscribe to this thread.
Old Account!
If this is your account, sign in to activate web presence data (sign in quarterly to keep active). Alternatively, you can subscribe to our monthly eMag with a valid email address.
Web Presence Hidden.
Once above is taken care of, full Profile content will display including back links, about me, my message, custom Profile html, social networking links, message board signature, company profile, etc.

Post ID #8121 (Level 1.15)  Reply to 8075
Reply Posted 10/30/2002 1:32:00 PM
Location=Las Vegas, NV USA 
Joined=18 years ago   MB Posts=442   KB Posts=19  

Revive Thread!

Add a comment to revive this old thread and make this archived thread more useful.

Write a Comment...
Full Editor
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P156A1
Enter key:
Icon: A Post    Thread    Idea    Important!    Cool    Sad    No    Yes    Includes a Link...   
Thread #8075 Counter
2195
Since 4/2/2008

Follow PrestwoodBoards on: 


©1995-2020 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech