Skip to content

Instantly share code, notes, and snippets.

View viniciussanchez's full-sized avatar
:octocat:
Share knowledge

Vinicius Sanchez viniciussanchez

:octocat:
Share knowledge
View GitHub Profile
@viniciussanchez
viniciussanchez / HandlerException.dpr
Created November 18, 2022 13:43
DPR do projeto de exemplo de como controlar as exceções de uma aplicação desenvolvida em Delphi
program HandlerException;
uses
Vcl.Forms,
Handler.Exception.Main in 'src\Handler.Exception.Main.pas' {FrmMain},
Handler.Exception in 'src\Handler.Exception.pas';
{$R *.res}
begin
@viniciussanchez
viniciussanchez / Handler.Exception.pas
Created November 18, 2022 13:41
Classe para controlar as exceções em Delphi
unit Handler.Exception;
interface
uses System.SysUtils;
type
TMyHandlerException = class
private
class procedure GerarLog(E: Exception);
@viniciussanchez
viniciussanchez / Handler.Exception.Main.pas
Created November 18, 2022 13:40
Gerando uma exceção no Delphi
procedure TFrmMain.btnGerarExceptionClick(Sender: TObject);
var
LValor: Integer;
begin
LValor := StrToInt('X');
end;
@viniciussanchez
viniciussanchez / Params.Const.pas
Created October 18, 2022 13:40
Parâmetros como constantes
function CompareStr(const S1, S2: string): Integer;
procedure Exemplo(var Value: Double);
begin
Value := 10;
end;
function Somar(const valor1, valor2: Double): Double;
begin
Result := valor1 + valor2;
@viniciussanchez
viniciussanchez / Out.pas
Created October 18, 2022 12:49
Parâmetros de saída
procedure GetInfo(out Info: SomeRecordType);
@viniciussanchez
viniciussanchez / Somar.Referencia.pas
Last active October 18, 2022 12:53
Somar por referência
procedure AddOne(var X, Y: Integer);
begin
X := X + 1;
Y := Y + 1;
end;
// depois que este código for executado, o valor de I será 3.
var
I: Integer;
begin
function Somar(valor1, valor2: Double): Double;
begin
Result := valor1 + valor2;
end;
@viniciussanchez
viniciussanchez / Dockerfile
Last active November 24, 2022 13:56
PAServer with Docker - Delphi (Linux)
# Docwiki
# https://docwiki.embarcadero.com/RADStudio/Sydney/en/Linux_Application_Development
FROM ubuntu:18.04
RUN apt update -y && apt upgrade -y && apt dist-upgrade -y
RUN apt install -y joe wget p7zip-full curl openssh-server build-essential zlib1g-dev libcurl4-gnutls-dev libncurses5
COPY ./LinuxPAServer20.0.tar.gz ./
RUN tar -xvf ./LinuxPAServer20.0.tar.gz
ENTRYPOINT ./PAServer-20.0/paserver -password=
@viniciussanchez
viniciussanchez / x-www-form-urlencoded.pas
Created August 25, 2021 14:33
x-www-form-urlencoded
procedure TServiceLogin.Example;
var
LResponse: IHTTPResponse;
LFormUrlencoded: TStringList;
LRequest: THTTPClient;
begin
LRequest := THTTPClient.Create;
LFormUrlencoded := TStringList.Create;
try
LFormUrlencoded.Add('grant_type=my-grant-type');
begin
qryUsuarios.SQL.Clear;
qryUsuarios.SQL.Add('select *');
qryUsuarios.SQL.Add(' from user');
qryUsuarios.SQL.Add(' where login = :login');
qryUsuarios.SQL.Add(' and password = :senha');
qryUsuarios.ParamByName('login').AsString := edtUsuario.Text;
qryUsuarios.ParamByName('senha').AsString := edtSenha.Text;
qryUsuarios.Open();
if qryUsuarios.IsEmpty then