Solved

turning off a specific compiler warning

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bunnyEars challenge 6 99
object oriented javascript web form 8 104
oracle global variables 4 63
QRReport  TQrmemo vertical stretching 1 42
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

911 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

22 Experts available now in Live!

Get 1:1 Help Now