Borland C++Builder 6 字符串操作太慢

Borland C++Builder 6 Strings operation is too slow

我有一个学期通行证的程序,但遇到了问题。它将文本读入 TStringList,然后在 TMemo 中对其进行操作。编译时一切正常。但是当我 运行 没有安装 Borland 的 EXE 文件时,除了这个程序之外,它在做任何其他事情时都会挂起,例如 运行 在它上面安装一个浏览器。它只发生在像 3000 行这样的大文件上。我该如何解决这个问题?

[Spektre 重构的表单源]

unit1.cpp

//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#include <strutils.hpp>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString NazwaPliku;
AnsiString szerstop;
AnsiString dlustop;
AnsiString final;
AnsiString Linia;
AnsiString Linia1;
TStringList *Lista=NULL;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner):TForm(Owner)
    {
    Lista = new TStringList;
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Wczytaj1Click(TObject *Sender)
    {
    if(OpenDialog1->Execute())
        {
        Lista->LoadFromFile(OpenDialog1->FileName);
        NazwaPliku=OpenDialog1->FileName;
        Memo1->Lines->LoadFromFile(NazwaPliku);
        }
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Zamknij1Click(TObject *Sender)
    {
    if (Application->MessageBox("Czy na pewno zakończyć?","Tak",MB_YESNO|MB_ICONQUESTION)==IDYES)
        {
        Application->Terminate();
        }
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Konwertuje1Click(TObject *Sender)
    {
    AnsiString Poczatek="<?xml version=\"1.0\" encoding=\"UTF-8\"?><kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><name>Ścieżka</name><description>.</description><Style id=\"yellowLineGreenPoly\"><LineStyle><color>7f00ffff</color><width>75</width></LineStyle><PolyStyle><color>7f00ff00</color></PolyStyle></Style><Placemark><name>Absolute Extruded</name><description>.</description><styleUrl>#yellowLineGreenPoly</styleUrl><LineString><extrude>1</extrude><tessellate>1</tessellate><altitudeMode>absolute</altitudeMode><coordinates>";
    AnsiString Koniec="</coordinates></LineString></Placemark></Document></kml>";
    Memo1->Clear();
    Memo1->Lines->Add(Poczatek);
    for(int i=0; i<Lista->Count; i++)
        {
        AnsiString str_linia=Lista->Strings[i];
        char* linia=str_linia.c_str();
        if(strstr(linia,"GPGGA")!=NULL)
            {
            int stopnies, stopnied, lpz;
            double czas, minutys, minutyd, szer_stop, dlu_stop;
            char ms, md;
            lpz=sscanf(linia, "$GPGGA,%lf,%2d%lf,%c,%3d%lf,%c", &czas, &stopnies, &minutys, &ms, &stopnied, &minutyd, &md);
            Sleep(0);
            if(lpz==7)
                {
                if(ms=='N') szer_stop=stopnies+(minutys/60.0);
                 else       szer_stop=-(stopnies+(minutys/60.0));
                if(md=='E') dlu_stop=stopnied+(minutyd/60.0);
                else        dlu_stop=-(stopnied+(minutyd/60.0));
                }
            Edit1->Text=FloatToStr(szer_stop);
            Edit1->Refresh();
            Edit2->Text=FloatToStr(dlu_stop);
            Edit2->Refresh();
            }
        AnsiString szerstop=Edit1->Text;
        szerstop=StringReplace(szerstop,",",".",TReplaceFlags());
        AnsiString dlustop=Edit2->Text;
        dlustop=StringReplace(dlustop,",",".",TReplaceFlags());
        AnsiString final=dlustop+","+szerstop;
        Memo1->Lines->Add(final);
        }
    Memo1->Lines->Add(Koniec);
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Wyczysc1Click(TObject *Sender)
    {
    Memo1->Clear();
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Zapiszjako1Click(TObject *Sender)
    {
    SaveDialog1->Execute();
    Memo1->Lines->SaveToFile(SaveDialog1->FileName);
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
    {
    if(Application->MessageBox("Czy na pewno zakończyć?","Tak",MB_YESNO | MB_ICONQUESTION)==IDNO)
        {
        Action=caNone;
        }
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Czcionka1Click(TObject *Sender)
    {
    if (FontDialog1->Execute());
        {
        Memo1->Font->Name=FontDialog1->Font->Name;
        Memo1->Font->Color=FontDialog1->Font->Color;
        Memo1->Font->Size=FontDialog1->Font->Size;
        Memo1->Font->Style=FontDialog1->Font->Style;
        }
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Info1Click(TObject *Sender)
    {
    ShowMessage("");
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::Filtruj1Click(TObject *Sender)
    {
    Memo1->Clear();
    AnsiString Linia1;
        {
        for(int j=0; j<Lista->Count;j++)
            {
            AnsiString str_linia1=Lista->Strings[j];
            char* linia1=str_linia1.c_str();
            if(strstr(linia1,"GPGGA")!=NULL)
            Memo1->Lines->Add(linia1);
            Sleep(0);
            }
        }
    }
//---------------------------------------------------------------------------
void __fastcall TForm1::PrzywrcTXT1Click(TObject *Sender)
    {
    Memo1->Clear();
    Memo1->Lines->LoadFromFile(NazwaPliku);
    }
//---------------------------------------------------------------------------

unit1.h

//$$---- Form HDR ----
//---------------------------------------------------------------------------

#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
#include <Dialogs.hpp>
#include <Buttons.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published:    // IDE-managed Components
    TMemo *Memo1;
    TOpenDialog *OpenDialog1;
    TPanel *Panel1;
    TSpeedButton *Wczytaj1;
    TSpeedButton *Zamknij1;
    TSpeedButton *Konwertuje1;
    TEdit *Edit1;
    TSaveDialog *SaveDialog1;
    TEdit *Edit2;
    TSpeedButton *Wyczysc1;
    TSpeedButton *Zapiszjako1;
    TFontDialog *FontDialog1;
    TSpeedButton *Czcionka1;
    TSpeedButton *Info1;
    TSpeedButton *Filtruj1;
    TSpeedButton *PrzywrcTXT1;
    void __fastcall Wczytaj1Click(TObject *Sender);
    void __fastcall Zamknij1Click(TObject *Sender);
    void __fastcall Konwertuje1Click(TObject *Sender);
    void __fastcall Wyczysc1Click(TObject *Sender);
    void __fastcall Zapiszjako1Click(TObject *Sender);
    void __fastcall FormClose(TObject *Sender, TCloseAction &Action);
    void __fastcall Czcionka1Click(TObject *Sender);
    void __fastcall Info1Click(TObject *Sender);
    void __fastcall Filtruj1Click(TObject *Sender);
    void __fastcall PrzywrcTXT1Click(TObject *Sender);
private:    // User declarations
public:     // User declarations
    __fastcall TForm1(TComponent* Owner);
void __fastcall TForm1::Idleloop(TObject *Sender, bool &Done);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif

unit1.dfm

object Form1: TForm1
  Left = 0
  Top = 0
  ClientHeight = 362
  ClientWidth = 619
  Color = clBtnFace
  Font.Charset = OEM_CHARSET
  Font.Color = clWindowText
  Font.Height = 14
  Font.Name = 'System'
  Font.Pitch = fpFixed
  Font.Style = [fsBold]
  OldCreateOrder = False
  OnClose = FormClose
  PixelsPerInch = 96
  TextHeight = 14
  object Memo1: TMemo
    Left = 0
    Top = 31
    Width = 619
    Height = 331
    Align = alClient
    ScrollBars = ssBoth
    TabOrder = 0
    ExplicitTop = 32
  end
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 619
    Height = 31
    Align = alTop
    TabOrder = 1
    object Wczytaj1: TSpeedButton
      Left = 34
      Top = 4
      Width = 23
      Height = 22
      Glyph.Data = {
        F6000000424DF600000000000000760000002800000010000000100000000100
        04000000000080000000CE0E0000C40E00001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
        77777777777777777777000000000007777700333333333077770B0333333333
        07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
        77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
        7007777777770777070777777777700077777777777777777777}
      OnClick = Wczytaj1Click
    end
    object Zamknij1: TSpeedButton
      Left = 232
      Top = 4
      Width = 23
      Height = 22
      Glyph.Data = {
        6E040000424D6E04000000000000360000002800000013000000120000000100
        18000000000038040000CE0E0000D80E00000000000000000000C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000FF
        FFFFC0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0C0C0C0000000FFFFFF
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0000000000000000000FFFFFFC0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000FFFFFFC0C0C0C0C0C0C0C0C0
        C0C0C0000000C0C0C0C0C0C0C0C0C0000000000000000000FFFFFFC0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0000000FFFFFFC0C0C0C0C0C0C0C0C0C0C0C0C0C0C000
        0000C0C0C0C0C0C0C0C0C0C0C0C0000000000000000000FFFFFFC0C0C0C0C0C0
        C0C0C0000000000000FFFFFFC0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0000000000000000000FFFFFFC0C0C000000000
        0000FFFFFFC0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0000000000000000000000000000000FFFFFFC0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0000000000000000000FFFFFFC0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0000000000000000000000000000000FFFFFFC0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000
        000000000000FFFFFFC0C0C0000000FFFFFFC0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0000000000000000000000000FF
        FFFFC0C0C0C0C0C0C0C0C0000000000000FFFFFFC0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0000000C0C0C0C0C0C0000000000000000000000000FFFFFFC0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0000000000000FFFFFFC0C0C0C0C0C0C0C0C0C0C0C000
        0000C0C0C0C0C0C0000000000000FFFFFFC0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0000000000000FFFFFFC0C0C0C0C0C0C0C0C0000000C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000}
      OnClick = Zamknij1Click
    end
    object Konwertuje1: TSpeedButton
      Left = 92
      Top = 4
      Width = 23
      Height = 22
      Glyph.Data = {
        6E040000424D6E04000000000000360000002800000013000000120000000100
        18000000000038040000C40E0000C40E00000000000000000000C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0000000000000000000000000000000
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C00000000000000000000000000000
        00000000C0C0C0000000C0C0C0000000FFFFFFFFFFFFFFFFFF000000C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000757575FFFFFFFFFFFFFFFFFF000000
        C0C0C0000000C0C0C0000000000000000000000000000000C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0000000757575757575757575757575000000C0C0C000
        0000C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0
        C0C0C0C0C0C0000000757575757575757575757575000000C0C0C00000000000
        00000000000000000000000000C0C0C0C0C0C0C0C0C0000000000000C0C0C0C0
        C0C0000000757575757575757575757575000000C0C0C0000000000000FFFFFF
        FFFFFFFFFFFF000000C0C0C0000000000000000000000000000000C0C0C00000
        00FFFFFFFFFFFFFFFFFF757575000000C0C0C000000000000000000000000000
        0000000000C0C0C0000000000000000000000000000000C0C0C0000000757575
        757575757575757575000000C0C0C0000000C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0000000000000C0C0C0C0C0C000000075757575757575
        7575757575000000C0C0C0000000000000000000000000000000000000000000
        C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C00000007575757575757575757575
        75000000C0C0C0000000000000FFFFFFFFFFFFFFFFFFFFFFFF000000C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000FFFFFFFFFFFFFFFFFFFFFFFF000000
        C0C0C0000000000000FFFFFFFFFFFFFFFFFFFFFFFF000000C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0000000FFFFFFFFFFFFFFFFFFFFFFFF000000C0C0C000
        0000000000FFFFFFFFFFFFFFFFFFFFFFFF000000C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0000000FFFFFFFFFFFFFFFFFFFFFFFF000000C0C0C00000000000
        00000000000000000000000000000000C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0000000000000000000000000000000000000C0C0C0000000C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0
        C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000}
      OnClick = Konwertuje1Click
    end
    object Wyczysc1: TSpeedButton
      Left = 150
      Top = 4
      Width = 23
      Height = 22
      Glyph.Data = {
        0E060000424D0E06000000000000360000002800000016000000160000000100
        180000000000D805000000000000000000000000000000000000C8D0D4C8D0D4
        C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0
        D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000C8D0
        D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8
        D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4
        0000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4
        C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0
        D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0
        D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8
        D0D4C8D0D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8
        D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4
        C8D0D4C8D0D4C8D0D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4
        C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0
        D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D40000
        00000000000000000000000000000000000000C8D0D4C8D0D4C8D0D4C8D0D4C8
        D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000C8D0D4C8D0D4C8D0D400
        0000C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0000000000000C8D0D4C8D0D4
        C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000C8D0D4C8D0D4
        C8D0D4000000C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000000000BFBF0000
        00C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000C8D0
        D4C8D0D4C8D0D4000000C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C0C000000000
        BFBF00BFBF000000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4
        0000C8D0D4C8D0D4C8D0D4C8D0D4000000FFFFFF00FFFFFFFFFF00FFFFFFFFFF
        00FFFF00000000BFBF00BFBF000000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0
        D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4000000FFFFFF00FFFFFFFF
        FF00FFFFFFFFFF00FFFF00000000BFBF00BFBF000000C8D0D4C8D0D4C8D0D4C8
        D0D4C8D0D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4000000FF
        FFFF00FFFFFFFFFF00FFFFFFFFFF00FFFF00000000BFBF00BFBF000000C8D0D4
        C8D0D4C8D0D4C8D0D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4
        C8D0D4000000FFFFFF00FFFFFFFFFF00FFFFFFFFFF00FFFF00000000BFBF0000
        00C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D4C8D0
        D4C8D0D4C8D0D4C8D0D4000000FFFFFF00FFFFFFFFFF00FFFFFFFFFF00FFFF00
        0000000000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000C8D0D4C8D0D4C8D0D4C8
        D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4000000FFFFFF00FFFFFFFFFF00FFFF
        FFFFFF00FFFF000000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000C8D0D4C8D0D4
        C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000000000000000
        00000000000000000000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000C8D0
        D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8
        D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4
        0000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4
        C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0
        D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0
        D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8
        D0D4C8D0D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8
        D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4
        C8D0D4C8D0D4C8D0D4C8D0D40000C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4
        C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0
        D4C8D0D4C8D0D4C8D0D4C8D0D4C8D0D40000}
      OnClick = Wyczysc1Click
    end
    object Zapiszjako1: TSpeedButton
      Left = 59
      Top = 4
      Width = 23
      Height = 22
      Glyph.Data = {
        F6000000424DF600000000000000760000002800000010000000100000000100
        04000000000080000000C40E0000C40E00001000000000000000000000000000
        8000008000000080800080000000800080008080000080808000C0C0C0000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00888888888888
        888888000000000000088044000FF0000408804400F99F000408804400F99F00
        04088044000FF0000408804444F99F444408804400F99F004408804088F999F8
        040880408F8F999F04088040F9F8F99F04088040F99F999F04088040F99999F8
        000880408F999F880808800000FFF00000088888888888888888}
      OnClick = Zapiszjako1Click
    end
    object Czcionka1: TSpeedButton
      Left = 175
      Top = 4
      Width = 23
      Height = 22
      Caption = 'A'
      Font.Charset = OEM_CHARSET
      Font.Color = clWindowText
      Font.Height = -21
      Font.Name = 'System'
      Font.Pitch = fpFixed
      Font.Style = [fsBold]
      ParentFont = False
      OnClick = Czcionka1Click
    end
    object Info1: TSpeedButton
      Left = 200
      Top = 4
      Width = 23
      Height = 22
      Caption = 'i'
      Font.Charset = OEM_CHARSET
      Font.Color = clWindowText
      Font.Height = -21
      Font.Name = 'System'
      Font.Pitch = fpFixed
      Font.Style = [fsBold]
      ParentFont = False
      OnClick = Info1Click
    end
    object Filtruj1: TSpeedButton
      Left = 118
      Top = 4
      Width = 23
      Height = 22
      OnClick = Filtruj1Click
    end
    object PrzywrcTXT1: TSpeedButton
      Left = 4
      Top = 4
      Width = 23
      Height = 22
      Glyph.Data = {
        F6000000424DF600000000000000760000002800000010000000100000000100
        04000000000080000000CE0E0000C40E00001000000000000000000000000000
        80000080000000808000800000008000800080800000C0C0C000808080000000
        FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
        77777777777777777777000000000007777700333333333077770B0333333333
        07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
        77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
        7007777777770777070777777777700077777777777777777777}
      OnClick = PrzywrcTXT1Click
    end
    object Edit1: TEdit
      Left = 268
      Top = 4
      Width = 80
      Height = 22
      TabOrder = 0
      Text = 'Edit1'
    end
    object Edit2: TEdit
      Left = 354
      Top = 4
      Width = 80
      Height = 22
      TabOrder = 1
      Text = 'Edit2'
    end
  end
  object OpenDialog1: TOpenDialog
    Left = 440
  end
  object SaveDialog1: TSaveDialog
    Left = 472
  end
  object FontDialog1: TFontDialog
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'Tahoma'
    Font.Style = []
    Left = 504
  end
end

最简单的是:

  1. 删除所有Sleep()s

  2. 添加Application->ProcessMessages()

    进入工作循环(每 n-th 次迭代一次)

  3. 在您仍在执行任何操作时将 lock 添加到任何操作中

    避免一次 运行 做多件事。您可以通过在执行前设置 Enabled=false; 并在执行后设置 Enabled=true; 来实现,对于任何会与您的操作冲突的按钮。您可以将所有按钮放在单个面板上,而不是 enable/disable 面板(甚至使其不可见)。

Threads 将是理想的选择,但如果您没有使用它们的经验,将很难实施和调试,因此我不建议采用这种方式。还有OnIdleEvent,在VCL中没有操作时,运行s。你可以把你的计算移到那里但是你需要按时间限制它所以划分操作所以它可以工作一段时间然后 return 到 VCL 然后再次可以继续.. .

您可以优化您的代码,例如将文本累积到 AnsiString 中然后将其作为整体添加而不是逐行添加到 TMemo 通常更快:例如:

AnsiString txt="";
txt+="123\r\n";
txt+="456\r\n";
txt+="789\r\n";
Memo1->Lines->Add(txt);

此外,如果我没看错的话,您正在根据我的口味进行许多字符串复制...

为什么使用 Edit1,Edit2 作为临时变量?这是缓慢的,因为 Edit1->Text 中的任何更改都会调用重绘和东西......为什么不使用一些 AnsiString 代替并在循环后填充 Edit1->Text ...