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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:48:28+00:00 2026-05-27T16:48:28+00:00

Lately, I have been noticing that anytime I use Rectangle variable with With…do statement,

  • 0

Lately, I have been noticing that anytime I use Rectangle variable with With…do statement, it doesn’t work at all for some reason.

For instance:

var bounds:=new Rectangle(0,0,0,0);

with bounds do
begin
  X:=1;
  Y:=2;
  Width:=33;
  Height:=44;
end;

bounds’ values remain zeros not whats in the with statement. However if I do the following, it works great.

var bounds:=new Rectangle(0,0,0,0);

bounds.X:=1;
bounds.Y:=2;
bounds.Width:=33;
bounds.Height:=44;

Is there any reason why it would do that.

  • 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-27T16:48:29+00:00Added an answer on May 27, 2026 at 4:48 pm

    What Hans Passant is trying to imply is that the “with” statement creates a copy of bounds, works on it, then throws it away. I don’t have enough information to verify that, but I feel that it’s unlikely – Delphi’s assignment operator works by reference, so implicit shallow copies don’t actually happen that often.

    However, “with” statements intentionally create a special kind of variable scoping hell. You could be grabbing a field inside bounds, or you could be grabbing a field from the containing method, or you could even be grabbing a field from a previous unclosed “with” statement. Automatic refactoring can’t touch a with statement. Adding a field to the class the with statement operates on can break your method.

    Consider

    with myLongNamedComponent.anotherLongNamedChild.pedanticRectangle do
    begin
        x:=1;
        y:=2;
        width:=33;
        height:=44;
    end;
    

    This is actually better written as

    var bounds := new Rectangle(0,0,0,0);
    bounds.x := 1;
    bounds.y := 2;
    bounds.width := 33;
    bounds.height := 44;
    myLongNamedComponent.anotherLongNamedChild.pedanticRectangle := bounds;
    

    TL:DR; the “with” statement is no longer considered good coding practice.

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

Sidebar

Related Questions

I have been doing some work lately with a Pre-compiled .NET3.5 app so i
Lately I have been finding that some of the ColdFusion applications on my production
I have been doing some research lately over my work project, i am trying
I have been reading a lot of Javascript lately and I have been noticing
Lately I have been playing a game on my iPhone called Scramble. Some of
I've been using Mercurial for some development lately and have been loving it. I'm
I am developing a project that lately have been taking off with increased popularity.
Lately I have been seeing an increasing number of design articles encouraging the use
I have been doing some catching up lately by reading about cloud hosting. For
Lately I have been doing some numerical method programming in C. For the bug

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.