Jump to content

balabuev

Members
  • Content Count

    89
  • Joined

  • Last visited

Community Reputation

15 Good

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. balabuev

    Main Form appearing issue..

    This can be achieved by setting form's PopupMode to pmAuto (can't say, why it's not default): if FCreatingMainForm then WndParent := 0 else WndParent := Application.ActiveFormHandle; // <------ ...
  2. balabuev

    Project always opens with .dpr file..

    I have related (opposite) question: how to prevent Delphi from showing main form of the project on project opening? I would prefer not to show anything.
  3. balabuev

    Main Form appearing issue..

    Can you also provide the code, which shows the dialog?
  4. balabuev

    Main Form appearing issue..

    You do something special in your application's code. It's obvious, because the issue cannot be reproduced with simple test project.
  5. Just as an idea: FFreeList can be implemented as a linked list, without any additional allocations.
  6. Ahh, sorry , missed that link. Then my previous message can be deleted.
  7. @dummzeuch Your problem is not in sorting algorithm at all. Trying to optimize sorting algorithm you just solving the wrong task. Even faster way will be to copy the data into some array, sort the array and then copy data back: type TDataItem = record S: string; O: TObject; Checked: Boolean; end; TData = array of TDataItem; var FData: TData; procedure TForm1.Button1Click(Sender: TObject); var c: Cardinal; i: Integer; c2: Cardinal; begin c := GetTickCount; CheckListBox1.Items.BeginUpdate; try SetLength(FData, CheckListBox1.Items.Count); // Copy data from UI for i := 0 to High(FData) do // control. begin // FData[i].S := CheckListBox1.Items[i]; // FData[i].O := CheckListBox1.Items.Objects[i]; // FData[i].Checked := CheckListBox1.Checked[i]; // end; // c2 := GetTickCount; SortList(0, High(FData), SortCompare); // Sort data in array. c2 := GetTickCount - c2; for i := 0 to High(FData) do begin CheckListBox1.Items[i] := FData[i].S; // Copy sorted data CheckListBox1.Items.Objects[i] := FData[i].O; // back. CheckListBox1.Checked[i] := FData[i].Checked; // end; finally CheckListBox1.Items.EndUpdate; c := GetTickCount - c; end; Edit1.Text := IntToStr(c); // Whole time, including UI updates. Edit2.Text := IntToStr(c2); // Sort only time. end; With 10000 items (!) this code run in: Whole time, including UI updates - 1.5 secs (the control is slow, nothing to do with that). Sort only time - 15 msecs. 15 msecs for sorting of 10000 items!
  8. I've uses the following test with 100 items in list (item count as in your initial post): procedure TForm1.FormCreate(Sender: TObject); var i: Integer; begin for i := 0 to 99 do // Just init the list with some data. begin CheckListBox1.Items.Add('Long long long string ' + IntToStr(Random(1000))); CheckListBox1.Items.Objects[i] := TObject(i); CheckListBox1.Checked[i] := (Random > 0.5); end; end; function TForm1.SortCompare(Item1, Item2: Integer): Integer; begin Result := CompareStr(CheckListBox1.Items[Item1], CheckListBox1.Items[Item2]); end; procedure TForm1.SortList(L, R: Integer; SCompare: TJCHListSortCompare); var I, J, P: Integer; tmpObj: TObject; tmpStr: string; tmpChecked: Boolean; begin repeat I := L; J := R; P := (L + R) shr 1; repeat while SCompare(I, P) < 0 do Inc(I); while SCompare(J, P) > 0 do Dec(J); if I <= J then begin // exchange I and J tmpStr := CheckListBox1.Items[I]; tmpObj := CheckListBox1.Items.Objects[I]; tmpChecked := CheckListBox1.Checked[I]; CheckListBox1.Items[I] := CheckListBox1.Items[J]; CheckListBox1.Items.Objects[I] := CheckListBox1.Items.Objects[J]; CheckListBox1.Checked[I] := CheckListBox1.Checked[J]; CheckListBox1.Items[J] := tmpStr; CheckListBox1.Items.Objects[J] := tmpObj; CheckListBox1.Checked[J] := tmpChecked; if P = I then P := J else if P = J then P := I; Inc(I); Dec(J); end; until I > J; if L < J then SortList(L, J, SCompare); L := I; until I >= R; end; procedure TForm1.Button1Click(Sender: TObject); var c: Cardinal; begin c := GetTickCount; CheckListBox1.Items.BeginUpdate; try SortList(0, CheckListBox1.Items.Count - 1, SortCompare); finally CheckListBox1.Items.EndUpdate; end; Edit1.Text := IntToStr(GetTickCount - c); end; With BeginUpdate/EndUpdate run time is 32 msecs. Without BeginUpdate/EndUpdate - 422 msecs. As for me, even 32 msecs is a way too big for sorting 100 items, but it not 2 seconds!
  9. Quite strange. Because in my tests they did a drammatic difference (I've used TCheckListBox for test).
  10. The price is - you cannot have DOMs, smaller than the OS memory page (4KB).
  11. balabuev

    Customizing source editor

    Customized colors in black theme + Inconsolata font. Quality image link: https://i.ibb.co/3dDkPNQ/image.png
  12. Sorting time like 2 seconds is not about sorting at all. It's absolutely crazy . The solution is simple: wrap your sorting with Items.BeginUpdate/Items.EndUpdate. And it's not so important which sort algorithm you will use. QuickSort is good enough.
  13. balabuev

    The Case of Delphi Const String Parameters

    var G: string; CriticalSection: ...; procedure TForm11.Button1Click(Sender: TObject); begin G := 7.ToString; // Init with non contant string data. for i := 0 to 1 do begin TTask.Run(procedure var localStr: string; begin CriticalSection.Asquire; // Fetch G into local variable under critical section protection. localStr := G; // CriticalSection.Release; // A(localStr); end); end; end; I claim, that even if we rewrite the code with critical section, it will still not work with your new implementation.
×