Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6835189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:12:10+00:00 2026-05-26T23:12:10+00:00

Why is that in Delphi Boolean variable initialized in global scope is false and

  • 0

Why is that in Delphi Boolean variable initialized in global scope is false and variable initialized in local scope is true?

Can we change any of the default values so that both (global and local variables) have the same values on initialization?

sample code

    unit Unit1;

    interface

    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, 
      Controls, Forms,Dialogs, StdCtrls;

    type
      TForm1 = class(TForm)
        Button1: TButton;
        Label1: TLabel;
        Label2: TLabel;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;

    var
      Form1: TForm1;
      bool1:boolean;

    implementation

    {$R *.dfm}

    procedure TForm1.Button1Click(Sender: TObject);
    var
     bool :boolean;
    begin
     if bool then
       label1.Caption:='true'
     else
       label1.caption:='false';
     if bool1 then
       label2.Caption:='true'
     else
       label2.caption:='false';

    end;

    end.

This displays me the result as

where true is label1 and false is label2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:12:10+00:00Added an answer on May 26, 2026 at 11:12 pm

    Local variables are actually not initialized, but global variables and object fields are initialized to zero (which means ‘false’ for boolean variables).

    Therefore you always have to initialize local variables yourself, compiler even generates a warning if you don’t.

    You should also check out Delphi documentation on variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently discovered that Delphi has a global variable called ReportMemoryLeaksOnShutdown, when set to
Are there any utilities that reformat Delphi code ? EDIT I am using Delphi
I've always heard that Delphi can do almost anything C++ can do...except write Windows
I was told more than once that Delphi handles dynamic classes better than static.Thereby
I've created a program in Delphi that uses Google's AJAX Search API to evaluate
I work on a program in Delphi that holds a lot of data, and
I have a site written in Delphi that needs to get data from a
I have an application written in Delphi that adds / updates contacts in outlook.
Is there a FOSS batch compiling solution for Delphi that takes version as an
I would like to declare a record in Delphi that contains the same layout

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.