Analitcs

Pesquisar no conteúdo do blog.atlabs.com.br

terça-feira, 23 de junho de 2015

DELPHI - Limpar String com Caracteres Especiais (PT_BR)

Reações: 
Função para alterar os caracteres acentuados do nosso idioma


function HasSpecialCharacters(AWord: String): Boolean;
var
  I : Integer;
begin
  Result := False;
  for I := 1 to Length(AWord) do
  begin
    if Result then Break;

    case AWord[I] of
      'á',
      'à',
      'ã',
      'ä',
      'â',

      'é',
      'è',
      'ë',
      'ê',

      'ì',
      'í',
      'ï',
      'î',

      'ò',
      'ó',
      'õ',
      'ö',
      'ô',

      'ù',
      'ú',
      'ü',
      'û',

      'ç',

      'À',
      'Á',
      'Ã',
      'Ä',
      'Â',

      'È',
      'É',
      'Ë',
      'Ê',

      'Ì',
      'Í',
      'Ï',
      'Î',

      'Ò',
      'Ó',
      'Õ',
      'Ô',
      'Ö',

      'Ù',
      'Ú',
      'Ü',
      'Û',

      'Ç' : Result := True;
    end;
  end;
end;

function ChangeSpecialCharacters(AWord: String): String;
var
  I : Integer;
begin
  for I := 1 to Length(AWord) do
  begin
    case AWord[I] of
      'á',
      'à',
      'ã',
      'ä',
      'â' : AWord[I] := 'a';

      'é',
      'è',
      'ë',
      'ê' : AWord[I] := 'e';

      'ì',
      'í',
      'ï',
      'î' : AWord[I] := 'i';

      'ò',
      'ó',
      'õ',
      'ö',
      'ô' : AWord[I] := 'o';

      'ù',
      'ú',
      'ü',
      'û' : AWord[I] := 'u';

      'ç' : AWord[I] := 'c';

      'À',
      'Á',
      'Ã',
      'Ä',
      'Â' : AWord[I] := 'A';

      'È',
      'É',
      'Ë',
      'Ê' : AWord[I] := 'E';

      'Ì',
      'Í',
      'Ï',
      'Î' : AWord[I] := 'I';

      'Ò',
      'Ó',
      'Õ',
      'Ô',
      'Ö' : AWord[I] := 'O';

      'Ù',
      'Ú',
      'Ü',
      'Û' : AWord[I] := 'U';

      'Ç' : AWord[I] := 'C';
    end;
  end;
  Result := AWord;
end;

segunda-feira, 15 de junho de 2015

SQL - Operadores LIKE

Reações: 
Retirado de: http://www.devmedia.com.br/usando-os-operadores-like-in-e-between-no-oracle/24687#ixzz3d9furRAi OPERADOR LIKE

Usa-se o operador LIKE em uma cláusula WHERE para procurar uma string padrão,
usando o LIKE com:
Sublinhado (_)
Porcentagem (%).

Sublinhado (_) - Serve para marcar uma posição Específica

Porcentagem (%) - Qualquer carácter a partir da posição especificada.

Leia mais em:

Usando os Operadores LIKE, IN e BETWEEN no Oracle


Select * from Pessoa Where Nome LIKE '_u%';

DELPHI - Converter nome curto do "DOS" em nome do completo Windows - Convert short name into full Windows name

Reações: 
Converte:


Isso c:\progra~1\micros~1\MoreGa~1

Nisso: c:\Program Files\Microsoft Games\More Games



Uses ShellAPI, SysUtils;
//...
Function GetLongFileName(Const FileName : String) : String; //convert short name into full windows name
var
  aInfo: TSHFileInfo;
begin
  if SHGetFileInfo(PChar(FileName),0,aInfo,Sizeof(aInfo),SHGFI_DISPLAYNAME)<>0 then
     Result:= extractfilepath(Filename)+String(aInfo.szDisplayName)
  else
     Result:= FileName;
end;

terça-feira, 9 de junho de 2015

DELPHI - AVI File Format

Reações: 
Nas minhas andanças pela internet achei alguns itens interessantes:

(Retirado do site: http://www.alexander-noe.com/  http://www.alexander-noe.com/video/documentation/avi.pdf)

Download Direto do BLOG
Http://atlabs.com.br/blog/download/PDF/AviFileFormat.pdf


Site em Russo:
http://delphiworld.narod.ru/base/avi_info2.html

Tradução do site em russo:
http://translate.google.com.br/translate?hl=pt-BR&sl=ru&u=http://delphiworld.narod.ru/base/avi_info2.html&prev=search


Fonte do site em russo:
unit AviInformation;

interface

uses
  SysUtils;
type
  //
  // structure containing avi file info
  //
  TAVIFileInfo = packed record
    AVIFileName: string;
    FileSize: double;
    ClipLength: double;
    VideoCodec: string[32];
    ClipBitrate: double;
    ClipWidth: Integer;
    ClipHeight: Integer;
    ClipFPS: double;
    AudioCodec: string[32];
    AudioBitRate: Integer;
    AudioSampleRate: Integer;
    AudioChannelCnt: Byte;
  end;
function ReadAviInfo(FileName: string; var ErrCode: Byte): TAVIFileInfo;

implementation
//
// Function for reading avi file
//

function ReadAviInfo(FileName: string; var ErrCode: Byte): TAVIFileInfo;
var
  // ????? ?????
  iFileHandle: Integer;
  // ??? ??????????????? ? AVI ?????
  Aviheadersize: integer;
  Vheadersize: integer;
  Aviheaderstart: integer;
  Vheaderstart: integer;
  Aheaderstart: integer;
  Astrhsize: integer;
  // ????????? ??????????
  TempFExt: string[5];
  TempSize: Integer;
  TempVcodec: string[5];
  TempAcodec: integer;
  TempMicrosec: integer;
  TempLengthInFrames: integer;
  TempAchannels: integer;
  TempAsamplerate: integer;
  TempAbitrate: integer;
  //???????? ??????
  Size: double;
  Length: double;
  Vcodec: string;
  Vbitrate: double;
  VWidth: integer;
  VHeight: integer;
  Fps: double;

  LengthInSec: double;
  Acodec: string;
  Abitrate: Integer;
  RetVal: TAVIFileInfo;
begin
  ErrCode := 0;
  TempAcodec := 0;
  TempAbitrate := 0;
  TempAsamplerate := 0;
  TempAchannels := 0;
  if not FileExists(FileName) then
  begin
    ErrCode := 1;
    exit;
  end;
  // ?????????
  iFileHandle := FileOpen(FileName, fmOpenRead);
  // ?????? ???????? ?? ??????????? ?????
  FileSeek(iFileHandle, 7, 0);
  FileRead(iFileHandle, TempFExt, 5);
  if copy(TempFExt, 0, 4) <> 'AVI ' then
  begin
    ErrCode := 2;
    exit;
  end;
  // ?????? ?????
  FileSeek(iFileHandle, 4, 0);
  FileRead(iFileHandle, TempSize, 4);
  // ?????? ?????? (needed to locate the audio part)
  FileSeek(iFileHandle, 28, 0);
  FileRead(iFileHandle, Aviheadersize, 4);
  // ????? ?????? (needed to locate the video part)
  Aviheaderstart := 32;
  // ??????????? (1000000 / TempMicrosec = fps)
  FileSeek(iFileHandle, Aviheaderstart, 0);
  FileRead(iFileHandle, TempMicrosec, 4);
  // ?????? ?? ???????
  FileSeek(iFileHandle, Aviheaderstart + 16, 0);
  FileRead(iFileHandle, TempLengthInFrames, 4);
  // ??????
  FileSeek(iFileHandle, Aviheaderstart + 32, 0);
  FileRead(iFileHandle, VWidth, 4);
  // ??????
  FileSeek(iFileHandle, Aviheaderstart + 36, 0);
  FileRead(iFileHandle, VHeight, 4);
  //calculate header size
  FileSeek(iFileHandle, Aviheaderstart + Aviheadersize + 4, 0);
  FileRead(iFileHandle, Vheadersize, 4);
  Vheaderstart := Aviheaderstart + Aviheadersize + 20;
  // Video Codec
  FileSeek(iFileHandle, Vheaderstart + 3, 0);
  FileRead(iFileHandle, TempVCodec, 5);
  Aheaderstart := Vheaderstart + Vheadersize + 8;
  FileSeek(iFileHandle, Aheaderstart - 4, 0);
  FileRead(iFileHandle, Astrhsize, 5);
  // Audio codec
  FileSeek(iFileHandle, Aheaderstart + Astrhsize + 8, 0);
  FileRead(iFileHandle, TempACodec, 2);
  // Audio ?????? (1 = mono, 2 = stereo)
  FileSeek(iFileHandle, Aheaderstart + Astrhsize + 10, 0);
  FileRead(iFileHandle, TempAchannels, 2);
  // Audio samplerate
  FileSeek(iFileHandle, Aheaderstart + Astrhsize + 12, 0);
  FileRead(iFileHandle, TempAsamplerate, 4);
  // Audio bitrate
  FileSeek(iFileHandle, Aheaderstart + Astrhsize + 16, 0);
  FileRead(iFileHandle, TempAbitrate, 4);
  // ????????? ????
  FileClose(iFileHandle);
  // ??????????? ????? ????? (????? ???????? ??????)
  Vcodec := copy(TempVcodec, 0, 4);
  if Vcodec = 'div2' then
    Vcodec := 'MS MPEG4 v2'
  else if Vcodec = 'DIV2' then
    Vcodec := 'MS MPEG4 v2'
  else if Vcodec = 'div3' then
    Vcodec := 'DivX;-) MPEG4 v3'
  else if Vcodec = 'DIV3' then
    Vcodec := 'DivX;-) MPEG4 v3'
  else if Vcodec = 'div4' then
    Vcodec := 'DivX;-) MPEG4 v4'
  else if Vcodec = 'DIV4' then
    Vcodec := 'DivX;-) MPEG4 v4'
  else if Vcodec = 'div5' then
    Vcodec := 'DivX;-) MPEG4 v5'
  else if Vcodec = 'DIV5' then
    Vcodec := 'DivX;-) MPEG4 v5'
  else if Vcodec = 'divx' then
    Vcodec := 'DivX 4'
  else if Vcodec = 'mp43' then
    Vcodec := 'Microcrap MPEG4 v3';
  // ???? ? ?????
  case TempAcodec of
    0: Acodec := 'PCM';
    1: Acodec := 'PCM';
    85: Acodec := 'MPEG Layer 3';
    353: Acodec := 'DivX;-) Audio';
    8192: Acodec := 'AC3-Digital';
  else
    Acodec := 'Unknown (' + IntToStr(TempAcodec) + ')';
  end;
  //Audio bitrate
  case (Trunc(TempAbitrate / 1024 * 8)) of
    246..260: Abitrate := 128;
    216..228: Abitrate := 128;
    187..196: Abitrate := 128;
    156..164: Abitrate := 128;
    124..132: Abitrate := 128;
    108..116: Abitrate := 128;
    92..100: Abitrate := 128;
    60..68: Abitrate := 128;
  else
    Abitrate := Round(TempAbitrate / 1024 * 8);
  end;
  // ??? ????????? ??????????
  Size := TempSize / 1024 / 1024;
  Fps := 1000000 / TempMicrosec; // FPS
  // Length in seconds
  LengthInSec := TempLengthInFrames / fps;
  //length in minutes
  Length := LengthInSec / 60;
  //Round(LengthInSec - (Int(LengthInSec / 60) * 60)));
  Vbitrate := (TempSize / LengthInSec - TempABitrate) / 1024 * 8;
  //fill up the file info structure
  RetVal.AVIFileName := FileName;
  RetVal.FileSize := Size;
  RetVal.ClipLength := Length;
  RetVal.VideoCodec := VCodec;
  RetVal.ClipBitrate := Vbitrate;
  RetVal.ClipWidth := VWidth;
  RetVal.ClipHeight := VHeight;
  RetVal.ClipFPS := FPS;
  RetVal.AudioCodec := Acodec;
  RetVal.AudioBitRate := Abitrate;
  RetVal.AudioSampleRate := TempAsamplerate;
  RetVal.AudioChannelCnt := TempAchannels;
  ReadAviInfo := RetVal;
end;

end.



unit UDemoAVI;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, AviInformation, StdCtrls;

type
  //
  // structure containing avi file info
  //
  TAVIFileInfo = packed record
    AVIFileName: string;
    FileSize: double;
    ClipLength: double;
    VideoCodec: string[32];
    ClipBitrate: double;
    ClipWidth: Integer;
    ClipHeight: Integer;
    ClipFPS: double;
    AudioCodec: string[32];
    AudioBitRate: Integer;
    AudioSampleRate: Integer;
    AudioChannelCnt: Byte;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    AVIVideoInfo: TMemo;
    OpenDialog1: TOpenDialog;
    AVIAudioInfo: TMemo;
    AVIGenInfo: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  FInfo: AviInformation.TAVIFileInfo;
  ErrCode: Byte;
begin
  if OpenDialog1.Execute then
  begin
    FInfo := AviInformation.ReadAviInfo(OpenDialog1.FileName, ErrCode);
    AviGenInfo.Clear;
    AVIVideoInfo.Clear;
    AVIAudioInfo.Clear;
    if ErrCode > 0 then
      exit;
    AviGenInfo.Lines.Add('AVI INFORMATION');
    AviGenInfo.lines.Add('FileName: ' + FInfo.AVIFileName);
    AviGenInfo.lines.Add('Size: ' + FormatFloat('#.## MB', FInfo.FileSize));
    AviGenInfo.Lines.Add('Length: ' + FormatFloat('#.## min.',
      FInfo.ClipLength));
    AVIVideoInfo.Lines.Add('VIDEO INFORMATION');
    AVIVideoInfo.Lines.Add('Codec: ' + FInfo.VideoCodec);
    AVIVideoInfo.Lines.Add('Bitrate: ' + FormatFloat('# Kbit/s',
      Finfo.ClipBitrate));
    AVIVideoInfo.lines.Add('Width: ' + IntToStr(Finfo.ClipWidth) + ' px');
    AVIVideoInfo.lines.Add('Height: ' + IntToStr(Finfo.ClipHeight) + ' px');
    AVIVideoInfo.Lines.Add('FPS: ' + FormatFloat('#.##', Finfo.ClipFPS));
    AVIAudioInfo.Lines.Add('AUDIO INFORMATION');
    AVIAudioInfo.Lines.Add('Codec: ' + Finfo.AudioCodec);
    AVIAudioInfo.Lines.Add('Bitrate: ' + FormatFloat('#.##',
      Finfo.AudioBitRate));
    AVIAudioInfo.Lines.Add('Audio sample Rate: ' +
      IntToStr(FInfo.AudioSampleRate));
    AVIAudioInfo.Lines.Add('Audio Channel Count: ' +
      IntToStr(FInfo.AudioChannelCnt));
  end;
end;

end.


// UDemoAVI.dfm
object Form1: TForm1
  Left = 441
  Top = 217
  Width = 687
  Height = 351
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 6
    Top = 3
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object AVIVideoInfo: TMemo
    Left = 6
    Top = 36
    Width = 185
    Height = 89
    Lines.Strings = (
      'AVIVideoInfo')
    TabOrder = 1
  end
  object AVIAudioInfo: TMemo
    Left = 6
    Top = 129
    Width = 185
    Height = 89
    Lines.Strings = (
      'AVIVideoInfo')
    TabOrder = 2
  end
  object AVIGenInfo: TMemo
    Left = 6
    Top = 222
    Width = 185
    Height = 89
    Lines.Strings = (
      'AVIVideoInfo')
    TabOrder = 3
  end
  object OpenDialog1: TOpenDialog
    Top = 6
  end
end
//UDemoAVI.dfm


Max Gehringer