quarta-feira, 29 de agosto de 2007

Detectando o número serial do HD

function SerialNum(FDrive: String): String;
var
serial: DWord;
DirLen, flags: DWord;
DLabel: array[0..11] of Char;
begin
try
GetVolumeInformation(PChar(FDrive+':\'), DLabel, 12, @serial, DirLen, flags, nil, 0);
result:= IntToHex(serial, 8);
except
result:= '';
end;
end;

Imprimir direto para impressora

procedure TForm1.Button1Click(Sender: TObject);
var
F: TextFile;
begin
AssignFile(F, 'LPT1');
Rewrite(F);
Writeln(F, 'Teste de impressao - Linha 1');
Writeln(F, 'Teste de impressao - Linha 2');
Writeln(F, #27#18+'Teste de impressao - Linha 3');
Writeln(F, #12); //ejeta a página
CloseFile(F);
end;

Verificando se o Delphi está aberto

Proteja aquele aplicativo ou objeto que você desenvolveu com esta rotina que identifica se o usuário está com o Delphi aberto (disponibiliza) ou fechado (trava a execucao).

function TForm1.JanelaExiste(classe, janela: String): Boolean;
var
pclasse, pjanela: array[0..79] of char;
begin
if classe = '' then
pclasse[0]:= #0
else
StrPCopy(pclasse, classe);
if janela = '' then
pjanela[0]:= #0
else
StrPCopy(pjanela, janela);

result:= (FindWindow(pclasse, pjanela) <> 0);
end;

function TForm1.DelphiCarregado: Boolean;
begin
result:= JanelaExiste('TPropertyInspector', 'Object Inspector');
end;

function TForm1.FormCreate(Sender: TObject);
begin
if DelphiCarregado then
showmessage('Delphi está ativo!')
else
begin
showmessage('Impossível iniciar aplicação!')
Application.Terminate;
end;
end;