Jump to content

Leaderboard


Popular Content

Showing content with the highest reputation on 01/06/21 in all areas

  1. Anders Melander

    smooth scaling of bitmaps

    Well, I couldn't resist the challenge so I have a nicely working implementation now. I'll create a pull request with it tonight (it's 6 in the morning here in Denmark) when I wake up again .
  2. Dalija Prasnikar

    The Case of Delphi Const String Parameters

    This problem is pure ARC problem. One instance of something is destroyed when other one is created and assigned because const parameter did not trigger reference counting mechanism - this is why const is used as speed optimization in the first place. Same thing that happens with strings happens with reference counted objects, but it is easier to see what happens with objects. You need form with memo and button to test following code. IFoo = interface function GetCount: Integer; function GetNumber: Integer; end; TFoo = class(TInterfacedObject, IFoo) private FNumber: Integer; public constructor Create(ANumber: Integer); destructor Destroy; override; function GetCount: Integer; function GetNumber: Integer; end; constructor TFoo.Create(ANumber: Integer); begin inherited Create; FNumber := ANumber; Form1.Memo1.Lines.Add('Created ' + FNumber.ToString); end; destructor TFoo.Destroy; begin Form1.Memo1.Lines.Add('Destroyed ' + FNumber.ToString); inherited; end; function TFoo.GetCount: Integer; begin Result := FRefCount; end; function TFoo.GetNumber: Integer; begin Result := FNumber; end; procedure TForm1.Button1Click(Sender: TObject); var s1: IFoo; procedure Test(const Value: IFoo); begin s1 := TFoo.Create(456); Memo1.Lines.Add('Test Value ' + Value.GetNumber.ToString); end; begin s1 := TFoo.Create(123); Test(s1); end; Output is: Created 123 Created 456 Destroyed 123 Test Value 123 Destroyed 456 It is pretty obvious that object instance holding 123 is destroyed before its value is printed. Value.GetNumber.ToString is accessing dangling pointer - if the memory where object or string previously occupied is not reused, you may get expected value even though that instance is dead, but if memory is reused in the meantime you will read content of some other data. Also the whole thing might crash, or it might not. Basically you get undefined behavior.
  3. Impressive: sorted reverse half random QuickSort(10000000): 0.69550 0.72872 not done 1.89622 QuickSort+(12)(10000000): 0.63999 0.65609 3.61170 1.70513 QuickSort+(15)(10000000): 0.63134 0.66484 3.65941 1.72658 QuickSort+(17)(10000000): 0.63200 0.65742 3.58655 1.73312 QuickSort+(20)(10000000): 0.59678 0.62114 3.60640 1.75100 TimSort(10000000): 0.02052 0.03282 0.11939 1.88033 QuickSort(100000000): 8.13450 8.50642 not done 21.52633 QuickSort+(12)(100000000): 7.16910 7.47369 45.95549 19.66967 QuickSort+(15)(100000000): 7.25634 7.49350 45.59182 19.57720 QuickSort+(17)(100000000): 7.15293 7.43410 46.06242 19.69688 QuickSort+(20)(100000000): 7.26109 7.46288 46.09772 20.61769 TimSort(100000000): 0.20487 0.33015 1.12082 23.05309 This is the result of a test sorting an array of 10 Million and 100 milliion integers on my computer. The values are the time in seconds. QuickSort is my regular quicksort implementation QuickSort+ is my optimized quicksort which: choses a pivot by selecting the median between elements Left, Right and (Left + Right) / 2 uses InsertionSort for small sets, if Right - Left < Cutoff (The value in parenthesis is the cutoff.) TimSort is the code from the link above, adjusted so it compiles with Delphi 2007 (no generics). Edit: Here is the source code. Note that It currently can only sort an array of integer.
  4. Nicklaus Wirth disagrees: https://en.wikipedia.org/wiki/Wirth's_law Bonus quote: What Intel giveth, Microsoft taketh away: https://en.wikipedia.org/wiki/Andy_and_Bill's_law
  5. Anders Melander

    smooth scaling of bitmaps

    The design time functionality hasn't changed so you don't need to recompile the packages. The easiest way to test it out would be to just copy the modified GR32_Image.pas to the source folder of your application. That way your application will compile with the new GR32_Image but your existing Graphics32 installation will not be affected. Once the changes are merged into the main Graphics32 branch you can update your Graphics32 installation and remove the local copy of GR32_Image.
  6. Okay, fine, as already said, I will do that. I hereby declare this thread to be closed 🙂
  7. Known issue (there are several discussion threads on this forum about it). That server was shutdown 2 months ago. Change GetIt's configuration to use https://getit.embarcadero.com instead of https://getit-104.embarcadero.com, see this discussion for how to do that:
  8. Paying the price for using a GUI control to hold your data, rather than to view your data.
  9. A.M. Hoornweg

    The Case of Delphi Const String Parameters

    "Out" parameters are an even bigger can of worms. I had refactored some code recently to use "OUT" parameters instead of VAR parameters (in order to more clearly document the intended use) and it had side effects that were hard to figure out. I thought my debugger had gone bananas. Try single-stepping through this code and watch the values. In hindsight, the cause is clear, but I find the compiler should throw a warning if it encounters such a situation. I now avoid OUT parameters. procedure tform2.test(OUT somestring:String; Defaultvalue:String); begin Somestring:=Defaultvalue; end; procedure TForm2.Button1Click(Sender: TObject); var t:string; begin t:='Testing 1-2-3'; Test(t,t); Showmessage(t); end;
  10. Attila Kovacs

    The Case of Delphi Const String Parameters

    I ran into this once function x(const input: string; var output: string): boolean; begun while we read input do alter output; end; if x(s,s) then; except that it wasn't easy to track down, it was a one time "achievement" in my life. Yet. given that, I consider every method having a const and var parameter of the same type as a time-bomb.
  11. Doug Rudd

    How to obtain a path to a folder inside the app bundle?

    In the deployment manager, if you put ".\assets\internal\" as the Remote Path, on start of your app it copies those files to a directory (if they dont already exist) that you can get with: tpath.GetDocumentsPath
  12. His legacy lives on through people like me using his code...
  13. Pat Foley

    Popup window with focus inside.

    Here's a screen shot of code realized.
  14. Pat Foley

    Popup window with focus inside.

    These forms show using CB items being created once referred then after. Showing the CB dropdown using messages. Using the CB to navigate other forms using only one list. Most of it is done by creating the ancillary form(s) in runtime. unit mainFocused; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) Button1: TButton; Button2: TButton; Edit1: TEdit; Memo1: TMemo; mainCB: TComboBox; procedure Button1Click(Sender: TObject); procedure FormClick(Sender: TObject); procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); procedure Button2Click(Sender: TObject); procedure Memo1Change(Sender: TObject); procedure Edit1Change(Sender: TObject); procedure FormCreate(Sender: TObject); procedure mainCBChange(Sender: TObject); private { Private declarations } public { Public declarations } formsSL, Headings: Tstrings; destructor Destroy; override; end; var Form1: TForm1; implementation uses formAncillary; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin Headings.text := edit1.Text; UF.IniZ(self, formsSL, Headings); end; procedure TForm1.Button2Click(Sender: TObject); var I,C: integer; F: TForm; Ctrl: Tcontrol; begin with Screen do begin for I := 0 to formCount - 1 do // downto 0 do begin F := Forms[I]; for C := 0 to F.ComponentCount - 1 do if F.Components[C] is TCombobox then begin Ctrl := F.Components[C] as Tcontrol; F.Show; Ctrl.parent.Show; Ctrl.Show; caption := F.Name; sleep(20); Ctrl.Perform(CB_ShowdropDown,1,0); application.ProcessMessages; sleep(1200); Ctrl.Perform(CB_ShowdropDown,0,0); application.ProcessMessages; Break; end; end; Headings.Text := Headings.Text + format(' %d',[I]);//I.ToString; end; end; destructor TForm1.Destroy; var I: integer; begin onclick := nil; with Screen do begin for I := formCount - 1 downto 0 do begin Forms[I].close; end; end; end; procedure TForm1.Edit1Change(Sender: TObject); begin Headings.Text := Edit1.Text; end; procedure TForm1.FormClick(Sender: TObject); begin Caption := 'clicked by ' + (Sender as TForm).Name; Self.Show; Button1.SetFocus; end; procedure TForm1.FormCreate(Sender: TObject); begin Headings := TStringList.Create; formsSL := mainCB.items; //borrowing created list formsSL.Add(self.Name); end; procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); begin Caption := 'Mouse over ' + (Sender as Tcontrol).Name; end; procedure TForm1.mainCBChange(Sender: TObject); var I: integer; S: String; begin for I := 0 to Screen.FormCount - 1 do begin S := mainCB.Items[mainCB.ItemIndex]; if S <> Screen.Forms[I].name then continue else Screen.Forms[I].show; end; end; procedure TForm1.Memo1Change(Sender: TObject); begin beep; end; end. Runtime created unit formAncillary; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls; type TfrmAncillary = class(TForm) Button1: TButton; Image2: TImage; remoteCB: TComboBox; procedure Button1Click(Sender: TObject); procedure remoteCBChange(Sender: TObject); procedure remoteCBDropDown(Sender: TObject); private { Private declarations } public { Public declarations } myHeadings, myLines: Tstrings; rfrmBoss: TForm; procedure IncomingTextUpdate(Sender: TObject); procedure ForwardFocus(Sender: TObject); procedure IniZ(bossForm: TForm; someLines, Headings: Tstrings); end; var UF : TfrmAncillary; implementation {$R *.dfm} procedure TfrmAncillary.Button1Click(Sender: TObject); begin beep; end; procedure TfrmAncillary.remoteCBChange(Sender: TObject); var I: integer; S: String; begin for I := 0 to Screen.FormCount - 1 do begin S := remoteCB.Items[remoteCB.ItemIndex]; if S <> Screen.Forms[I].name then continue else Screen.Forms[I].show; end; end; procedure TfrmAncillary.remoteCBDropDown(Sender: TObject); begin remoteCB.Items := myLines; remoteCB.Text := myHeadings.Text; end; procedure TfrmAncillary.ForwardFocus(Sender: TObject); begin rfrmBoss.OnClick(self); end; procedure TfrmAncillary.IncomingTextUpdate(Sender: TObject); begin remoteCB.Invalidate; end; procedure TfrmAncillary.IniZ(bossForm: TForm; someLines, Headings: Tstrings); begin Application.CreateForm(TfrmAncillary, UF); with UF do begin mylines := someLines; myHeadings := Headings; remoteCB.Items := someLines; name := 'UF_' + Screen.FormCount.ToString; myLines.Add(name); Caption := name; setbounds(10,20,360,270); rfrmBoss := bossForm; onclick := ForwardFocus; onmousedown := nil; onmouseMove := bossForm.OnMouseMove; Color := RGB(random(255),random(255),random(255)); show; end; end; end.
×