-2

I have a program for semester pass and have a problem. It reads text into a TStringList then operates on it in a TMemo. Everything is OK when compiling. But when I run the EXE file without Borland installed, it hangs when doing anything else than just this program, for example running a browser on top of it. It happens only with big files like 3000 lines. How can I solve this?

[reconstructed Form source by 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
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • 1
    Welcome to StackOverflow. Please provide a peace of your source code in order to help you. – J. Piquard Jan 14 '17 at 20:28
  • 2
    Off hand, it sounds like you are performing a long-running operation in the context of the main UI thread, blocking the main message loop from processing new UI messages in a timely manner. This will make the app appear frozen until the operation is complete and control returns to the message loop. DO NOT block the main thread. Perform long operations in a separate worker thread. Otherwise your operation needs to pump the main message queue periodically, such as with `Application.ProcessMessages()`, or at least use the Form's `Update()` method to process pending UI paint messages. – Remy Lebeau Jan 15 '17 at 04:31
  • to me it more sound like memory leak and or array overrun somewhere (in IDE is memory handled a bit differently then without it) I would try CodeGuard (In project option) first to detect problems. Also take a look at this: [bds 2006 C hidden memory manager conflicts](http://stackoverflow.com/a/18016392/2521214) You need to add that to each `struct` and `class` you are using to prevent such problems. From the feedback to that QA is this also issue in **BCB6** The link at the end of the answer is also useful do debug this... But without any code we can just guess – Spektre Jan 15 '17 at 11:09
  • In **BCB6** there is also the problem with wrongly added to project headers. If you got `*.cpp,*.h` files which are not forms then they should not be added to project but included instead. Files added to project are compiled differently and if not VCL form or generated stuff then it can cause unforseen problems. Have a lot of troubles with this in past when I was forced to use BCB6 (which is btw the worst of all BCB, the best was BCB5 and now BDS2006 have no knowledge on the latter from series)... – Spektre Jan 15 '17 at 11:18
  • And last thing I can think of is conflict between function and variable names as people tend to use English names starting with Uper case letter like `Draw` etc causing also a lot of troubles latter on especially in BCB6... – Spektre Jan 15 '17 at 11:24
  • @Spektre I still use BCB6 every day at work. What you say about non-VCL/generated files is simply not true. I have hundreds of such files in my projects and they compile just fine. – Remy Lebeau Jan 15 '17 at 18:09
  • @RemyLebeau then may be some content (that we was using) was conflicting then ... There were never compilation errors but the executable was usually not doing what it should like ignoring events, not calling functions etc ... Have seen this behavior many times but only on BCB6 and only when project got more complex. It was years back so may be some patch did fix it by now ... – Spektre Jan 15 '17 at 18:46
  • I think is threads problem as far as I found. Need to create multi thread but I dont know how. I started doing this but have problem with movig to thread my tstring list. I dont know how. Is there option to create thread in unit 1 instead of creating new thread by new-file-thread?? – Krzysiek Mikulski Jan 20 '17 at 20:20
  • http://pastebin.com/wdHTHqz4 Here is my code of the program. It simply load txt, gets coordinates from it and convert to kml. Im really a begginer but found it fun and want to make myslef fully satisfied with my work. As it is now doesnt satisfy me. It hang only on Konwertuje and Filtruj as there is a loop and it work longer – Krzysiek Mikulski Jan 20 '17 at 20:30
  • adding lines to memo one by one with `Memo1->Lines->Add` gets very slow as it redraws the window every time you add one line ... i would recommend building all memo content in a memory buffer and then assigning it to the memo in one go at the end – M.M Jan 21 '17 at 10:05
  • `Sleep(0);` will slow down your program, remove that – M.M Jan 21 '17 at 10:06
  • I reconstructed your App (my poland is rusty but the Class names are straightforward so I am confident I did it correctly) main form source and added it to your Question do you have also sample input file will be a good idea to add it here so anyone can test on your data (can use www.ulozto.net for bigger files)? – Spektre Jan 21 '17 at 10:33

1 Answers1

1

The simplest will be:

  1. Remove all Sleep()s

  2. Add Application->ProcessMessages()

    into working loop (once for every n-th iteration)

  3. Add lock to any operations while you are still doing any stuff

    to avoid multiple things to run at a time. You can do this by set Enabled=false; before execution and Enabled=true; after, for any button that would conflict your operation. You can put all the buttons on single Panel and enable/disable the panel instead (or even make it invisible).

Threads would be ideal for this but if you got no experience with them it will be hard to implement and debug so I do not recommend to go this way. There is also the OnIdleEvent which runs when no operations is done in VCL. You could move your computations there but you need to throttle it by time so divide the operation so it works for a while then return to VCL and after that again can continue ...

You can optimize your code for example it is usually faster to accumulate text into AnsiString and then add it as whole instead of adding to TMemo line by line for example:

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

Also If I see it right you are doing to many string copying for my taste ...

Why are you using Edit1,Edit2 as temp variable? That is SLOOW as any change in Edit1->Text will invoke repaint and stuff ... Why not use some AnsiString instead and fill the Edit1->Text after loop ...

Community
  • 1
  • 1
Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Ok you close is or whatewer you are doing with this. I did as followed: 1,2,3 point - did all. It really helped. Speeded up program by not using edit just writing directly into string and operating on string. Like this: AnsiString szerstop=FloatToStr(szer_stop); szerstop=StringReplace(szerstop,",",".",TReplaceFlags()); AnsiString dlustop=FloatToStr(dlu_stop); dlustop=StringReplace(dlustop,",",".",TReplaceFlags()); AnsiString final=dlustop+","+szerstop; Lista1->Add(final); – Krzysiek Mikulski Jan 24 '17 at 22:28
  • Nest thing is I cant work on ansistrings as it comletely breakes my file structure. So instead I used one more TStringsList and now it works. One List for TXT and one for KML. It really speeded up program. All this helped me as much as I needed. In some free time will try multi threading but probably not on borland 6 and not c++. Thanks a lot – Krzysiek Mikulski Jan 24 '17 at 22:32
  • @KrzysiekMikulski if this was helpful you can vote up, if wrong you can vote down (the triangle arrows above and below the big zero in top left corner of answer). If this lead to solution you can accept (checker in the same place) so others may quickly see what is helpful and what not. If you did not vote before I think there are some badges awarded the first time ... Hold/Close/Delete is only for questions that are not suited for this site or poorly written all others stays (unless owner deletes them on its own) so it can help others That is why title and tags are important (better search) – Spektre Jan 25 '17 at 08:23