Solved

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

Posted on 2004-04-23
4
263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month5 days, 23 hours left to enroll

627 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