Jump to content

3ddark

Members
  • Content Count

    5
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. The sort function is working. But when I sort for 100000 rows, it works very slowly. What suggestions do you have for better performance. I'm only sorting for one column at a time. No multiple sorting procedure TStringGrid.SortStringGrid(ACol: Integer); var i, j : Integer; LTemp: TStringList; LSortType: TSortMode; LCompResult: Boolean; begin Perform(WM_SETREDRAW, 0, 0); LTemp := TStringList.Create; try LSortType := smNone; for i := Self.FixedRows to Self.RowCount - 2 do begin for j:= i+1 to Self.RowCount-1 do begin //first sort or another column sort if (FSortType = smNone) or (FSortType = smDesc) or ((FSortType = smAsc) and (FSortCol <> ACol)) then begin if AnsiCompareText(Self.Cells[ACol, i], Self.Cells[ACol, j]) = GreaterThanValue then begin LTemp.Assign(Self.Rows[j]); Self.Rows[j].Assign(Self.Rows[i]); Self.Rows[i].Assign(LTemp); end; LSortType := smAsc; end else if (FSortType = smAsc) and (FSortCol = ACol) then //sort same column asc to desc begin if AnsiCompareText(Self.Cells[ACol, i], Self.Cells[ACol, j]) = LessThanValue then begin LTemp.Assign(Self.Rows[i]); Self.Rows[i].Assign(Self.Rows[j]); Self.Rows[j].Assign(LTemp); end; LSortType := smDesc; end; end; end; FSortType := LSortType; FSortCol := ACol; finally LTemp.free; Perform(WM_SETREDRAW, 1, 0); Invalidate; end; end;
  2. 3ddark

    MsgWaitForMultipleObjects Usage

    This is another solution unit MsgWaitForMultiple; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.SyncObjs; type TForm3 = class(TForm) Memo1: TMemo; Button1: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private public Event: TEvent; end; var Form3: TForm3; implementation {$R *.dfm} procedure TForm3.Button1Click(Sender: TObject); var Thrd : TThread; begin Event.ResetEvent; Thrd := TThread.CreateAnonymousThread( procedure begin Sleep(10000); Event.SetEvent; end ); Thrd.Start; while Event.WaitFor(0) = wrTimeOut do begin WaitMessage; Application.ProcessMessages; end; Memo1.Lines.Add('Thread bitti'); end; procedure TForm3.FormCreate(Sender: TObject); begin Event := TEvent.Create(nil, True, False, ''); end; end.
  3. 3ddark

    MsgWaitForMultipleObjects Usage

    @FPiette Add for loging I added deliberately
  4. How to wait for the above thread to finish before the main thread freezes? procedure TForm2.Button1Click(Sender: TObject); var Thrd : TThread; msg: tagMSG; Ret: Cardinal; begin Thrd := TThread.CreateAnonymousThread( procedure begin Sleep(10000); Memo1.Lines.Add('End of Thread'); end ); Thrd.Start; //The thread above is waiting for 10 seconds within itself. We will wait for the above thread to finish before the main thread freezes Ret := MsgWaitForMultipleObjects(0, Thrd, True, INFINITE, QS_ALLINPUT); //use with WaitMessage case Ret of WAIT_OBJECT_0: ; WAIT_OBJECT_0+1: ; WAIT_TIMEOUT: ; end; Memo1.Lines.Add('Thread finish'); end;
  5. 3ddark

    StringGrid Row Move

    Hello, I want to move rows in StringGrid, a Delphi component. (Delphi 7, TStringGrid) I fill the information in the stringrid as shown in the picture below. I also adjust the stringgrid settings. There is no problem with move to row sGrid.FixedCols := 1; sGrid.FixedRows := 1; sGrid.Options := sGrid.Options + [goRowMoving]; procedure TFormX.sGridMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var gc: TGridCoord; begin if Sender is TStringGrid then begin if TStringGridX(Sender).GridState in [gsRowMoving] then begin TStringGrid(Sender).MouseToCell(X, Y, gc.X, gc.Y); //get the row number of the first selected row FFromIndex := gc.Y; end; end; end; procedure TFormX.sGridMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); var gc: TGridCoord; begin if Sender is TStringGrid then begin if TStringGridX(Sender).GridState in [gsRowMoving] then begin TStringGrid(Sender).MouseToCell(X, Y, gc.X, gc.Y); FToIndex := gc.Y; end; end; end; procedure TFormX.sGridMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); var gc: TGridCoord; begin if Sender is TStringGrid then begin if TStringGridX(Sender).GridState in [gsRowMoving] then begin TStringGrid(Sender).MouseToCell(X, Y, gc.X, gc.Y); //here I know which lines you can go Caption := IntToStr(gc.X) + ':' + IntToStr(gc.Y); end; end; end; procedure TFormX.sGridRowMoved(Sender: TObject; FromIndex, ToIndex: Integer); begin //it also says which row to move to which row. //How can I cancel this operation if it is not the row I want. end; From the attached picture, Example 1-) I can move the A9 code on line 10 between lines 2 and 15. I want to prevent the move outside of these lines. Example 2-) F code in line 20 can be moved to lines 1, 16, 23, 27. I will also move F1 and F2 lines under this F code. When the move starts, I find the lines where the move can be done (1,16,23,27) what I really want it may seem like a complicated situation. How do I cancel only the line move job? How do I make it move over only the lines I want in the move? Thanks in advance.
×