Solved

turning off a specific compiler warning

Posted on 2011-02-15
4
446 Views
Last Modified: 2012-06-27
I have this function defined in unit1 and used by unit2.


function Store: Boolean;
begin
 Table.Update;             <-------- Warning here: 'Variable Table might not be initialized'
 blabla;
end;

Open in new window


The variable 'Table' is defined in Unit1 in IMPLEMENTATION section, so it is not visible from Unit2. It must remain like this. 'Table' it is initialized in Unit1 in the TableInit function:

function TableInit(CONST FileName: string): Boolean;    { Create table }
begin
 Table:= TMyTable.Create(FileName,'Tabel1'); 
 blabla;
end;

Open in new window


I call TableInit somewhere in Unit2 to init 'Table' but obviously the compiler cannot know this.
How can I convince the compiler that Table is initialized so it will stop showing that warning.
0
Comment
Question by:cubic77
[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 32

Accepted Solution

by:
Ephraim Wangoya earned 500 total points
ID: 34896863

You should not even try to turn off such warnings, These are very important especially when you are writing large projects.

You can just initialize the Table in Unit1 it two ways

1. When declaring the table
     var
        Table: TTable = nil;

2. initialization section at the end of the unit
    initialization
      Table := nil


0
 
LVL 4

Expert Comment

by:cebasso
ID: 34896942
to disable warnings in a specific part of code you can use

{$Warnings Off}

to enable again

{$Warnings On}

in your case

function Store: Boolean;
begin
 {$Warnings Off}
 Table.Update;
 blabla
end;
0
 

Author Comment

by:cubic77
ID: 34897002
@ewangoya

>You should not even try to turn off such warnings
I don't want that. I should be out of my mind to want to turn of hints or warnings.
:)


I will try your code.
0
 

Author Closing Comment

by:cubic77
ID: 34897007
thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

628 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