Solved

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

Posted on 2004-04-23
4
249 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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