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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:34:50+00:00 2026-05-15T06:34:50+00:00

i have a simple program that sorts a text file according to length of

  • 0

i have a simple program that sorts a text file according to length of words per line
this program works without problems in my xp based old machine
now i run this program on my new win7/intel core i5 machine, it freezes whole system and back normal after it finishes it’s work.

i’v invastigated the code and found the line causing the freeze

it was this specific line…

caption := IntToStr(i) + '..' + IntTostr(ii);

i’v changed it to

 caption :=   IntTostr(ii);  //slow rate change

and there is no freeze

and then i’v changed it to

caption :=   IntTostr(i);  //fast rate change

and it freeze again

my procedure code is

 var tword : widestring;
      i,ii,li : integer;
 begin   
     tntlistbox1.items.LoadFromFile('d:\new folder\ch.txt');
     tntlistbox2.items.LoadFromFile('d:\new folder\uy.txt');
     For ii := 15 Downto 1 Do //slow change
      Begin
        For I := 0 To TntListBox1.items.Count - 1 Do //very fast change
        Begin     
          caption := IntToStr(i) + '..' + IntTostr(ii); //problemetic line               
          tword := TntListBox1.items[i];
          LI := Length(tword);
          If lI = ii Then
          Begin             
            tntlistbox3.items.Add(Trim(tntlistbox1.Items[i]));
            tntlistbox4.items.Add(Trim(tntlistbox2.Items[i]));
          End;
        End;
      End;
    end;

any idea why ? and how to fix it?
i use delphi 2007/win32

  • 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-15T06:34:50+00:00Added an answer on May 15, 2026 at 6:34 am

    Is this happening inside an event handler on a form? I’m going to guess taht it is. In that case, “Caption” is in the scope of the form. The form’s caption text isn’t managed by the VCL, but by Windows, and if you’re sending a new WM_SETTEXT message on every iteration of the loop.

    A thorough explanation of why this is doing what it’s doing would require knowledge of Windows internals that I don’t have, but if I were to take a guess, I’d say it’s something like this:

    Every time you send that WM_SETTEXT message with a new caption, Windows checks to make sure it’s not identical to the existing caption. If it is, it can exit immediately. That’s why the infrequent change (the one that only uses ii) doesn’t slow your system down. But if it does change on every iteration, then Windows has to perform some sort of task switch in order to change it.

    As for why that would bog down the entire system under a Vista kernel (including Win7) but not XP, that’s completely outside my area of expertise. But if you’re trying to do this as some sort of progress indicator, there are better ways, especially if this loop is as tight as it looks.

    The best way to handle progress updates in a tight loop is to count iterations and only fire once every X times. (100 or 1000 can be good values for X, depending on how many times it’s running and how fast the whole thing takes.) This is basically what the ii only option does. You could also try putting a Progress Bar on the form to measure progress instead of doing it through the form’s caption.

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

Sidebar

Related Questions

I have a simple Tray icon program that opens a site using System.Diagnostics.Process.Start(URL) And
I have two simple while loops in my program that I feel ought to
I have a relatively simple select statement in a VB6 program that I have
I have a simple script which is used to start another program. This other
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I have the need to express simple conditionals as program input. The input must
Does anyone have sample code to copy open (in-use and locked by another program)
I have simple regex \.*\ for me its says select everything between and ,
Ok, i have simple scenario: have two pages: login and welcome pages. im using
In general, is it a best practice to have simple POJO Java classes implement

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.