Solved

turning off a specific compiler warning

Posted on 2011-02-15
4
430 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
  • 2
4 Comments
 
LVL 32

Accepted Solution

by:
ewangoya 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

760 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

18 Experts available now in Live!

Get 1:1 Help Now