Solved

turning off a specific compiler warning

Posted on 2011-02-15
4
443 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

Industry Leaders: 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

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to 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…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

749 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