Solved

Name of form and panel the same?

Posted on 2002-03-12
5
151 Views
Last Modified: 2010-04-05
Hi
Delphi allows you to put a panel on a form and change its name to Form1. This generates a lot of problems because now the compiler does not know whether I am refering to the panel or the form. Is this a bug? If not how do I specify which object I am accessing. I am using D5Ent.
Doing a Form1:=Nil causes a lot of strange problems.

Groete
Gerhardus
0
Comment
Question by:flooder
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
Motaz earned 50 total points
ID: 6855959
inside events you can use this:

Form1.Caption:= 'Hi'; // This will affect Panel caption

Self.Caption:= 'Hi'; // This will affect Form caption

Outside form:

Form1 means the form
Form1.Form1 means the panel

why did u need Form1:= nil??

Motaz
0
 

Expert Comment

by:gooder
ID: 6856004
Form1 is the instance of the form you create, when there is no object named 'form1' also;
If any, the way to access this form is to call 'Self' but not 'Form1' . And 'Form1' now is referenced to the object having this name.
                           so?
0
 
LVL 1

Author Comment

by:flooder
ID: 6856007
I create my forms runtime and when I free them I set them to nil.

Groete
Gerhardus
0
 
LVL 7

Expert Comment

by:Motaz
ID: 6856025
how did you create forms at run-time?

if you assign an owner to your created forms, then you cann't free them manually, instead the owner will free them which this owner is freed, so that if the owner attempt to free already freed forms, access violation will occure.

Another solution is to set nill to the owner of your forms such as:

var
  Form: TForm;
begin
  Form:= TForm.Create(nil);
  Form.Show;
 ....
  Form.Free;
  Form:= nil;
end;

Motaz
0
 
LVL 1

Author Comment

by:flooder
ID: 6856061
if not assigned(myform) then
  myform:=tmyform.create(nil)
myform.show or myform.showmodal

events for myform
onclose
  Action:=cafree;
ondestroy
  myform:=nil;

This is in short how I do this

Groete
Gerhardus
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question