[Delphi] Get MD5 Checksum


var
 IdMD5: TIdHashMessageDigest5;
 FS: TFileStream;
begin
IdMD5 := TIdHashMessageDigest5.Create;
FS := TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite);
try
Result := IdMD5.HashStreamAsHex(FS);
finally
FS.Free;
IdMD5.Free;
end;
end;

[Delphi] Get path with Drag and Drop


//OnCreate

DragAcceptFiles(Handle, True);

//Procedure
procedure TForm2.WMDROPFILES(var Msg: TWMDropFiles);
var
 i, amount: Integer;
 FileName: array[0..MAX_PATH] of Char;
begin
 inherited;
 try
 Amount := DragQueryFile(Msg.Drop, $FFFFFFFF, FileName, MAX_PATH);
 for i := 0 to (Amount - 1) do
 begin
 DragQueryFile(Msg.Drop, i, FileName, MAX_PATH);
 //FileName에 파일/폴더 path가 들어옵니다. 
 finally
 DragFinish(Msg.Drop);
 end;
end;

 

[Delphi] Html to String


var
IdHTTP: TIdHTTP;
Stream: TStringStream;
begin
IdHTTP := TIdHTTP.Create(nil);
Stream := TStringStream.Create;
try
try
IdHTTP.Get('URL', Stream);
JenkinsParsingResult := Stream.DataString;
except
//exception Raise... (URL is not valid)
end;
finally
tmr1.Enabled := True;
Stream.Free;
IdHTTP.Free;
end;
end;

[Delphi] Proccess is running?


var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
Result := False;
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
begin
Result := True;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;

[Delphi] Checksum

function GetCheckSum(FileName: string): DWORD;
var
 F: file of DWORD;
 P: Pointer;
 Fsize: DWORD;
 Buffer: array [0..500] of DWORD;
begin
 FileMode := 0;
 AssignFile(F, FileName);
 Reset(F);
 Seek(F, FileSize(F) div 2);
 Fsize := FileSize(F) - 1 - FilePos(F);
 if Fsize > 500 then Fsize := 500;
 BlockRead(F, Buffer, Fsize);
 Close(F);
 P := @Buffer;
 asm
 xor eax, eax
 xor ecx, ecx
 mov edi , p
 @again:
 add eax, [edi + 4*ecx]
 inc ecx
 cmp ecx, fsize
 jl @again
 mov @result, eax
 end;
end;