5 Dicas de Delphi

5 Dicas de Delphi

Neste post mostraremos 5 dicas de desenvolvimento na linguagem de programação Delphi.

5 Dicas de Delphi
5 Dicas de Desenvolvimento Delphi

Verificando se uma data esta em um final de semana

Esta função testa se a data informada como parâmetro está em um fim de semana (Sábado ou Domingo).
Em caso de positivo retorna True. Se não retorna False

Function FimdeSemana (dData : TDateTime) : boolean;
begin
result := false;
if (DayOfWeek(dData) = 1) or (DayOfWeek(dData) = 7) Then
result := true;
end;

Verificando atributo do arquivo

Crie uma variável do tipo word, por ex., Attributes.

Depois, atribua a esta variável o valor retornado por FileGetAttr.

Exemplo a seguir

var
Attributes: Word;
begin
Attributes := FileGetAttr( ‘nomedoarquivo’ );

// Supondo 4 CheckBoxe’s, 1 para cada atributo, Ok?
CheckBox1.Checked := (Attributes and faReadOnly) = faReadOnly;
CheckBox2.Checked := (Attributes and faArchive) = faArchive;
CheckBox3.Checked := (Attributes and faSysFile) = faSysFile;
CheckBox4.Checked := (Attributes and faHidden) = faHidden;

Compara dois valores e retorna o menor

function Min(A, B: Integer): Integer;
begin
if A < B then
Result := A
else
Result := B;
end;

Efetua a leitura de um valor Integer no registro

Como efetuar a leitura de um valor Integer no registro via programação Delphi

function ReadRegInt(sPath: HKey; sOpenKey,sNomeValue: string; sValue: integer): integer;
// requer a Registry na clausula uses da unit
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := sPath;
if Reg.KeyExists(sOpenKey) then
begin
Reg.OpenKey(sOpenKey, false);
if Reg.ValueExists(sNomeValue) then
try
result := Reg.ReadInteger(sNomeValue)
except
result := -1
end
else
result := -1
end
else
result := -1
finally
Reg.Free;
end;
end;

 

Efetua a leitura um valor string no registro

Efetua a leitura um valor string no registro

function ReadRegString(sPath: HKey; sOpenKey,sNomeValue, sValue: string): string;
// requer a Registry na clausula uses da unit
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := sPath;
if Reg.KeyExists(sOpenKey) then
begin
Reg.OpenKey(sOpenKey, false);
if Reg.ValueExists(sNomeValue) then
try
result := Reg.ReadString(sNomeValue)
except
result := ‘Invalido’
end
else
result := ‘invalido’
end
else
result := ‘invalido’
finally
Reg.Free;
end;
end;

📒 Livros sobre o Delphi

Veja mais livros sobre desenvolvimento de aplicações em Delphi, acessando aqui!

Obrigado

Espero que estas dicas sejam úteis para você ou tenha lhe ajudado de alguma forma.

Se você gostou, compartilhe estas dicas com um amigo ou participe de nossas redes sociais.

Conhece alguma outra dica ?

Envie para nos em nossa página do Facebook.

Caso queira nos incentivar a criar mais conteúdos como este, prestigie nossos anunciantes.

Um Grande Abraço e até a próxima dica!

Posts Similares