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 8990919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:36:36+00:00 2026-06-15T22:36:36+00:00

This is just a very simple question to which i can’t find a good

  • 0

This is just a very simple question to which i can’t find a good clear answer to. I don’t quite have the time to read all the documentation for this since i’m in a time crunch.

But here it is.

I have made a new class on top of my TForm class like so:

 Bucket = Class
   glass: Integer;
   steel: Integer;
 End;

I then create a couple of objects in a method which belongs to TForm1

procedure TForm1.getMarbles;
var
  objPlastic: Bucket;
  objAlu: Bucket;

begin
  // Initialize objects
  objPlastic := Bucket.Create;
  objAlu := Bucket.Create;

  // Get Values from edtBox
  val(Edit1.Text, objPlastic.steel, code);
  val(Edit2.Text, objAlu.steel, code);
  val(Edit3.Text, objPlastic.glass, code);
  val(Edit4.Text, objAlu.glass, code);
end; 

My problem is that I don’t know how to use these objects in other methods. I tried defining them in every way i know so far in the other methods I want to use them in, but I can’t get it to work.

Here is the method and what I have it currently set to (which returns 0 all the time):

procedure TForm1.marbleDrop(kind: string);
var
  objPlastic: Bucket;
  I: Integer;
begin
  objPlastic := Bucket.Create;
  if kind= 'plastic' then // the function is receiving this parameter
  begin
    for I := 0 to objPlastic.glass do
    begin
      showmessage(inttostr(objPlastic.glass)); //returns 0
    end;
  end;

end;

Sorry for this kind of question, but i couldn’t find a better way.

BTW, this is a simplified version of the code I am using. I did my best to get out any typos since it’s a translation of what I am actually using, but it’s mainly about the idea. I don’t have typos in my code in delphi.

  • 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-15T22:36:38+00:00Added an answer on June 15, 2026 at 10:36 pm

    In other to access the objects across methods, you have to either:

    1. declare the objects as members of the Form class:

      type
        TForm1 = class(TForm);
        ...
        private
          objPlastic: Bucket;
          objAlu: Bucket;
        ...
        end;
      
      procedure TForm1.getMarbles;
      begin
        // Initialize objects
        if objPlastic = nil then objPlastic := Bucket.Create;
        if objAlu = nil then objAlu := Bucket.Create;
      
        // Get Values from edtBox
        objPlastic.steel := StrToIntDef(Edit1.Text, 0);
        objAlu.steel := StrToIntDef(Edit2.Text, 0);
        objPlastic.glass := StrToIntDef(Edit3.Text, 0);
        objAlu.glass := StrToIntDef(Edit4.Text, 0);
      end;
      
      procedure TForm1.marbleDrop(kind: string);
      begin
        if (kind = 'plastic') and (objPlastic <> nil) then
        begin
          ShowMessage(IntToStr(objPlastic.glass));
        end;
      end;
      
    2. pass them as parameters of the methods themselves:

      procedure TForm1.getMarbles(objPlastic, objAlu: Bucket);
      begin
        // Get Values from edtBox
        if objPlastic <> nil then
        begin
          objPlastic.steel := StrToIntDef(Edit1.Text, 0);
          objPlastic.glass := StrToIntDef(Edit3.Text, 0);
        end;
        if objAlu <> nil then
        begin
          objAlu.steel := StrToIntDef(Edit2.Text, 0);
          objAlu.glass := StrToIntDef(Edit4.Text, 0);
        end;
      end;
      
      procedure TForm1.marbleDrop(objWhichKind: Bucket);
      begin
        if objWhichKind <> nil then
        begin
          ShowMessage(IntToStr(objWhichKind.glass));
        end;
      end;
      
      procedure TForm1.someMethod();
      var
        objPlastic: Bucket;
      begin
        objPlastic := Bucket.Create;
        getMarbles(objPlastic, nil);
        marbleDrop(objPlastic);
        objPlastic.Free;
      end;
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This must be very simple. But I just can't seem to find the proper
this might be a very simple question, but I could not find an answer
Ok, very simple question this time (though the answer seems elusive for I can't
Alright, this is a very simple question. I just installed Tomcat 6 on my
This seems to me like a very simple question, but I can't seem to
Ok this is more of general technology/approach question. We have a very simple web
This is a very simple question. I often find myself wanting to create a
This may turn out to be a simple question with a very complex answer,
My question is very simple, but I couldn't find an answer. I'm sorry if
This is probably a simple question, but I'm not very good at PostGIS and

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.