How do I run a command-line program in Delphi?

An example using ShellExecute(): procedure TForm1.Button1Click(Sender: TObject); begin ShellExecute(0, nil, ‘cmd.exe’, ‘/C find “320” in.txt > out.txt’, nil, SW_HIDE); Sleep(1000); Memo1.Lines.LoadFromFile(‘out.txt’); end; Note that using CreateProcess() instead of ShellExecute() allows for much better control of the process. Ideally you would also call this in a secondary thread, and call WaitForSingleObject() on the process handle to … Read more

What’s the simplest way to call Http POST url using Delphi?

Using Indy. Put your parameters in a StringList (name=value) and simply call Post with the URL and StringList. function PostExample: string; var lHTTP: TIdHTTP; lParamList: TStringList; begin lParamList := TStringList.Create; lParamList.Add(‘id=1’); lHTTP := TIdHTTP.Create; try Result := lHTTP.Post(‘http://blahblahblah…’, lParamList); finally lHTTP.Free; lParamList.Free; end; end;

How do I sort a generic list using a custom comparer?

The Sort overload you should be using is this one: procedure Sort(const AComparer: IComparer<TMyRecord>); Now, you can create an IComparer<TMyRecord> by calling TComparer<TMyRecord>.Construct. Like this: var Comparison: TComparison<TMyRecord>; …. Comparison := function(const Left, Right: TMyRecord): Integer begin Result := Left.intVal-Right.intVal; end; List.Sort(TComparer<TMyRecord>.Construct(Comparison)); I’ve written the Comparison function as an anonymous method, but you could also … Read more

Rotate bitmap by real angle

tl;dr; Use GDI+ SetWorldTransform With WinAPI’s SetWorldTransform you can transform the space of device context: rotate, shear, offset, and scale. This is done by setting the members of a transform matrix of type XFORM. Fill its members according the documentation. procedure RotateBitmap(Bmp: TBitmap; Rads: Single; AdjustSize: Boolean; BkColor: TColor = clNone); var C: Single; S: … Read more