Solved

turning off a specific compiler warning

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Specific format 21 196
mapBully challenge 6 127
PHP question(s) about order of output 9 62
Slow Restore if incremental backups using RDiff.exe 4 17
Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
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 goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

786 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