turning off a specific compiler warning

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

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

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 }
 Table:= TMyTable.Create(FileName,'Tabel1'); 

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.
Question by:cubic77
  • 2
LVL 32

Accepted Solution

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
        Table: TTable = nil;

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


Expert Comment

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;
 {$Warnings Off}

Author Comment

ID: 34897002

>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.

Author Closing Comment

ID: 34897007

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error 1.1 400 Bad request idhttp delphi 18 140
word0 challenge 3 100
Delphi XE7 Firemonkey - text turns black after tabbing between applications on android 5 38
Problem to Alipay 10 42
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

792 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