Solved

Name of form and panel the same?

Posted on 2002-03-12
5
149 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now