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

  • SEARCH
  • Home
  • 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 7791257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:49:48+00:00 2026-06-01T21:49:48+00:00

I’ve got the following code in Form1. public { Public declarations } cas: integer;

  • 0

I’ve got the following code in Form1.

public
  { Public declarations }
  cas: integer;
end;

Then I work with the variable, and then I call another form with Form2.ShowModal; On Form2 I try to execute the following: Label9.Caption:=Format('%ds',[Form1.cas]);. But no matter what I do, in Form1 ‘cas’ is assigned the proper value but in Form2 it always shows “0s”. Why does that happen?

EDIT:

Now I have in the first unit called ‘kolecka’ this

var
  Form1: TForm1;
  barvy: array[1..6] of TColor;
  kola: array[1..22] of TShape;
  valid: integer;
  bezi: boolean;
  presnost: real;
  skore: integer;
  chyb: integer;
  kliku: integer;
  cas: integer;

and this in the other unit called ‘dialog’:

implementation

uses
  kolecka;

{$R *.dfm}

procedure Statistiky();
begin
  With Form2 do begin
    Label8.Caption:=IntToStr(kolecka.skore);
    Label9.Caption:=Format('%ds',[kolecka.cas]);
    Label10.Caption:=IntToStr(kolecka.cas);
    Label11.Caption:=IntToStr(skore);
    Label12.Caption:=Format('%.2f%%',[presnost]);
  end;
end;

But it still doesn’t work.. still shows a zero.

EDIT2:

I feel like every answer says something different and I’m very confused..

EDIT3: This is how ‘cas’ is manipulated in Form1

procedure TForm1.Timer3Timer(Sender: TObject);
begin
  cas:=cas+1;
  Form1.Label5.Caption:=IntToStr(cas);
end;

FOUND IT!

Meh. I figured out where was the problem.
I was assigning the label captions on Form2 Create and not Show, so of course they were at 0 >.>

  • 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-06-01T21:49:49+00:00Added an answer on June 1, 2026 at 9:49 pm

    In your original question, you declared a field in an object, and you thought it was a global, perhaps?

    unit unit1;
    
    interface 
    
    uses Stuff;
    
    type 
     TForm1 = class(TForm)
       public
         THisIsAFieldInAnObject:Integer;
     end
    
    var
      ThisIsAGlobal:Integer;
    
    implementation
    
    uses OtherStuff;
    
    ...
    

    Notice where you put globals above. Global variables are not fields inside a class. Where you put something, when you write code is called “the context you are in”. Inside a class declaration, something like public makes sense as a visiblity specifier. It does not make things global, it makes them visible to users of the class.

    To access the global, access it as unitName.VariableName, and don’t forget to add ‘Uses unitName’ to the other unit.

    Update You are now correctly accessing the global variable, and it doesn’t contain the value you expected. That’s where we start debugging. Set a breakpoint on the place where you set the variable, and on any other place where it is changed back to 0. Now set a breakpoint on the place where you read the variable. I find that variable writes work better when they actually happen, and when they aren’t over-written by a subsequent write to the same place, that contains a different value. Variables are like a box which contains a number. Zero things writing to it (the code you thought got called did not get called) or two things writing to it (the thing you think should be there but is not there because the second write zapped the first value) are common sources of your sort of confusion.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
i got an object with contents of html markup in it, for example: string

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.