Delphi My Documents Path

uses System.IOUtils

TPath.GetDocumentsPath

Windows 7: C:\Users\USERNAME\Documents
Windows XP: C:\Documents and Settings\USERNAME\My Documents

Advertisements

How to create Self-Signed Code Signing Certificate

Install Windows SDK for Windows 7

cmd with Admin Priviliges

cd C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin

makecert -r -pe -n “CN=My CA” -ss CA -sr CurrentUser -a sha256 -cy authority -sky signature -sv MyCA.pvk MyCA.cer

certutil -user -addstore Root MyCA.cer

makecert -pe -n “CN=My SPC” -a sha256 -cy end -sky signature -ic MyCA.cer -iv MyCA.pvk -sv MySPC.pvk MySPC.cer

pvk2pfx -pvk MySPC.pvk -spc MySPC.cer -pfx MySPC.pfx

signtool sign /v /f MySPC.pfx /t http://timestamp.url MyExecutable.exe

Timestamp URLs:
http://timestamp.verisign.com/scripts/timstamp.dll
http://timestamp.globalsign.com/scripts/timstamp.dll
http://timestamp.comodoca.com/authenticode

Delphi HttpResponse Error Solution

Error: No mapping for the Unicode character exists in the target multi-byte code page

var
HttpClient: THttpClient;
HttpResponse: IHttpResponse;
begin
HttpClient := THTTPClient.Create;
try
HttpResponse := HttpClient.Get(AURL);
//Result := HttpResponse.ContentAsString();
Result := HttpResponse.ContentAsString(TEncoding.ANSI);
finally
HttpClient.Free;
end;
end;

Delphi Elevated Application Drag & Drop

Dragging & dropping files (Explorer) to elevated application:

procedure SetDragAndDropOnSystemsWIthUAC(Wnd : HWND; IsEnabled : boolean);
type
  TChangeWindowMessageFilter = function(Msg : Cardinal; Action : Word) : Bool; stdcall;
const
  Msg_Add = 1;
  WM_COPYGLOBALDATA = $49;
var
  DllHandle : THandle;
  ChangeWindowMessageFilter : TChangeWindowMessageFilter;
begin
  DllHandle := LoadLibrary('user32.dll');
  if DllHandle > 0 then
  begin
    ChangeWindowMessageFilter := GetProcAddress(DllHandle, 'ChangeWindowMessageFilter');
    if Assigned(ChangeWindowMessageFilter) then
    begin
      DragAcceptFiles(Wnd, IsEnabled);
      ChangeWindowMessageFilter(WM_DROPFILES, Msg_Add);
      ChangeWindowMessageFilter(WM_COPYGLOBALDATA, Msg_Add);
    end;
  end;
end;

Get MachineGUID using Delphi

var
  fReg:TRegistry;
  GUIDStr:String;
begin
  try
    fReg:= TRegistry.Create(KEY_WRITE OR KEY_WOW64_64KEY);
    fReg.RootKey:=HKEY_LOCAL_MACHINE;
    if fReg.OpenKeyReadOnly('\SOFTWARE\Microsoft\Cryptography') then
      begin
        GUIDStr:=freg.ReadString('MachineGuid');
        edit1.Text:=GUIDStr;
      end;
  finally
    fReg.Free;
  end;
end;

Delphi Reverse Tab

BLOCK INDENT AND UNINDENT: SHIFT-CTRL-I and SHIFT-CTRL-U

You can indent a whole block of code at once by selecting that block and pressing SHIFT-CTRL-I. The whole block will indent by the “Block Indent” value in Editor Properties. Perfect for if you want to add begin and end around a large block of code!

If you decide you have indented too far, SHIFT-CTRL-U has the opposite effect.

As a side note, you can edit how much these shortcut keys indent by selecting Tools -> Editor Properties and changing the “Block indent” value.