Solved

Newbie: variable 'f' might not have been initialize.

Posted on 2004-04-23
4
251 Views
Last Modified: 2010-04-05
Purpose of this procedure is to display the child form if one already exist. I dont know how to remove the warning. Newbie to delphi. how do i fix this?

procedure TMainForm.CreateMDIChild(frm: TFormClass);
var
  i:integer;
  bCreated:boolean;
  f:TForm;
begin
    bCreated:=False;
    for i:=0 to MainForm.MDIChildCount-1 do
    begin
      if MainForm.MDIChildren[i] is frm then
      begin
        f:=MainForm.MDIChildren[i] as frm;
        bCreated:=True;
        Break;
      end;
    end;

    if not bCreated then
    begin
      frm.Create(Application);
    end
    else
    begin
        f.Show; //<-----<< warning here
    end;
end;
0
Comment
Question by:Jerry_Pang
  • 2
4 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 10906550
Can't You do like this?

procedure TMainForm.CreateMDIChild(frm: TFormClass);
var
  i:integer;
  bCreated:boolean;
  f:TForm;
begin
    bCreated:=False;
    for i:=0 to MainForm.MDIChildCount-1 do
    begin
      if MainForm.MDIChildren[i] is frm then
      begin
        f:=MainForm.MDIChildren[i] as frm;
        bCreated:=True;
        f.Show;
        Break;
      end;
    end;

    if not bCreated then
    begin
      frm.Create(Application);
    end
end;

0
 
LVL 12

Accepted Solution

by:
Ivanov_G earned 50 total points
ID: 10907195

   You seen warning because    
   f:=MainForm.MDIChildren[i] as frm;
   is in IF statement and some times the condition can be FALSE. You can about this if you type

 begin
    F := nil;
    ....
    // YOUR CODE
 
0
 
LVL 9

Author Comment

by:Jerry_Pang
ID: 10914728
mokule,
i cant. because that will always create a an instance of a form.
if not bCreated then
 Create the form.
else
 show the form.
endif

0
 
LVL 17

Expert Comment

by:mokule
ID: 10915712

You probably did not notice that the same is in my code :)
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

789 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