Sniffer de red

Indicando una IP, podemos ver el tráfico de datos de entrada y salida.

Podemos filtrar por puerto o por tipo de trama (SYS, RST, ACK, FIN, URG)



Autor:

Pierre Freby  pfreby@hotmail.com



Descargar codigo fuente












Juego de damas avanzado


Aquí tienen el conocido juego de las damas. Tiene como opción la posibilidad de jugar humano-máquina, máquina-máquina, giro de tablero y varios niveles (beginer, intermediate, expert).












El juego de las líneas en 3D










 Juego interesante, adictivo y muy bien programado.





Autor: Alexander Izmukhambetov 





Librería Exif


Biblioteca de funciones para crear, editar y modificar los metadatos exif y ipctc en archivos de imágenes con formato jpg.













Autor:


Chris Rolliston (http://delphihaven.wordpress.com/).





Licence:


MPL 1.1 (text at http://www.mozilla.org/MPL/MPL-1.1.html).





Features





·        Exif parsing is 100% pure Delphi code — doesn’t use (say) LibExif or LibTiff, GDI+, WIC, or even Windows.pas.





·        Reads and writes both small- and big-endian data.





·        Surfaces both standard Exif and Windows Explorer tags, and provides access to the tags of some maker note types too.





·        Doesn’t corrupt internal maker note offsets when data is rewritten, and takes account of the Microsoft-defined OffsetSchema tag.





·        Can optional write XMP data as per the XMP Exif schema.





·        Includes an IPTC reader/writer class as well.














Delphi y Arduino






Aquí tienen 2 programas que permiten controlar desde Delphi la placa de hardware arduino, uno es para leer la temperatura desde el sensor LM35 y el otro para apagar y encender unos leds.


Buscando en la red también encontré esta página donde explica cómo se interconecta el sensor LM35.



Autor: Roberto Ramirez






Descargar programa para leer la temperatura









PROGRAMA PARA CONTROLAR LEDs

{*

 * Delphi LEDs Control

 * -----------------

 * Controls the state (ON/OFF) of 5 LEDs connected to an Arduino Board

 * on Digital Pins 2,3,4,5,6 thru the serial comm

 *

 * Created April 02 2009

 * copyleft 2009 Roberto Ramirez
 * Full Source code at http://www.thepenguincult.com/proyectos/arduino-delphi-control/
 *
 *}

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, CPort, CPortCtl, Menus;

type
  TForm1 = class(TForm)
    btn_connect: TButton;
    ComPort1: TComPort;
    StatusBar1: TStatusBar;
    btn_Setup: TButton;
    chk_led1: TCheckBox;
    chk_led2: TCheckBox;
    chk_led3: TCheckBox;
    chk_led4: TCheckBox;
    chk_led5: TCheckBox;
    btn_loop: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    procedure btn_connectClick(Sender: TObject);
    procedure btn_SetupClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure chk_led1Click(Sender: TObject);
    procedure chk_led2Click(Sender: TObject);
    procedure chk_led3Click(Sender: TObject);
    procedure chk_led4Click(Sender: TObject);
    procedure chk_led5Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btn_loopClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn_connectClick(Sender: TObject);
begin
  if ComPort1.Connected then
      begin

      btn_connect.Caption:='Connect';  // Toggle the caption of Connection Button
      btn_Setup.Enabled:=True;         // If not connected, lets enable the Setup Button
      btn_loop.Enabled:=false;         // Knight Rider demo button is disabled at first

      // This block resets the state of all Leds to Off
      // According to Arduino Code the Chars A,B,C,D,E are used
      // to set Digital Pins (2-6) to LOW
      comport1.WriteStr('A');
      comport1.WriteStr('B');
      comport1.WriteStr('C');
      comport1.WriteStr('D');
      comport1.WriteStr('E');
      //-----------------------------------------------
      // This block resets the state of all Check Boxes to Unchecked
      chk_led1.Checked:=false;
      chk_led2.Checked:=false;
      chk_led3.Checked:=false;
      chk_led4.Checked:=false;
      chk_led5.Checked:=false;
      //-----------------------------------------------
      ComPort1.Close;                  // COM Port in use is closed

      statusbar1.Panels[1].Text:='Disconnected';  // Status bar is set to display connection info

      // This block disables the check boxes
      // so the user cannot change them if COM Port is disconnected
      chk_led1.Enabled:=false;
      chk_led2.Enabled:=false;
      chk_led3.Enabled:=false;
      chk_led4.Enabled:=false;
      chk_led5.Enabled:=false;
      //------------------------------------------------
     end

    else
      begin
      btn_connect.Caption:='Disconnect';        // Toggle the caption of Connection Button
      btn_Setup.Enabled:=False;                 // If not connected, lets disable the Setup Button
      btn_loop.Enabled:=true;                   // Now that conection is posible Knight Rider demo button is enabled
      ComPort1.Open;                            // COM Port in use is finally opened
      statusbar1.Panels[1].Text:='Connected';   // Status bar is set to display connection info

      // This block enables the check boxes
      // so the user can change them to set LED states when COM Port is connected
      chk_led1.Enabled:=true;
      chk_led2.Enabled:=true;
      chk_led3.Enabled:=true;
      chk_led4.Enabled:=true;
      chk_led5.Enabled:=true;
      //------------------------------------------------
      end
end;



procedure TForm1.btn_SetupClick(Sender: TObject);
begin
comport1.ShowSetupDialog;                                   // Opens the predefined Setup Dialog (part of ComPort component)
statusbar1.Panels[0].Text:='Port in use ' + comport1.Port;  // Status bar is set to display Port in use after setup dialog
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
statusbar1.Panels[0].Text:='Port in use ' + comport1.Port;  // Status bar is set to display predefined Port in use at begining of program execution

  if comport1.Connected=true then
    statusbar1.Panels[1].Text:='Connected'                  // Status bar is set to display connection info at begining of program execution
    else
    statusbar1.Panels[1].Text:='Disconnected'
  end;


// Next are the procedures to turning ON and OFF each led using the variables
// defined on both Arduino code and delphi code.
// Sending the predifined vars thru serial comm (on byte at the time)
// Ports 2,3,4,5,6 are turned ON by sending it corresponding var 1,2,3,4,5
// and they are turned OFF by sending it corresponding var A,B,C,D,E


procedure TForm1.chk_led1Click(Sender: TObject);
begin

    if chk_led1.Checked=true then
    comport1.WriteStr('1')
    else
    comport1.WriteStr('A')

end;

procedure TForm1.chk_led2Click(Sender: TObject);
begin
    if chk_led2.Checked=true then
    comport1.WriteStr('2')
    else
    comport1.WriteStr('B')
end;

procedure TForm1.chk_led3Click(Sender: TObject);
begin
    if chk_led3.Checked=true then
    comport1.WriteStr('3')
    else
    comport1.WriteStr('C')
end;

procedure TForm1.chk_led4Click(Sender: TObject);
begin
    if chk_led4.Checked=true then
    comport1.WriteStr('4')
    else
    comport1.WriteStr('D')
end;

procedure TForm1.chk_led5Click(Sender: TObject);
begin
    if chk_led5.Checked=true then
    comport1.WriteStr('5')
    else
    comport1.WriteStr('E')
end;

// Here ends the ON/OFF procedures for each led


procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if ComPort1.Connected then
      begin
        comport1.WriteStr('A');     // If the application is closed, its good to leave
        comport1.WriteStr('B');     // everything as we found it at start.
        comport1.WriteStr('C');     // So we reset all the leds to OFF
        comport1.WriteStr('D');
        comport1.WriteStr('E');
        ComPort1.Close;
        end
end;

procedure TForm1.btn_loopClick(Sender: TObject);
begin

// We turn off all Led Check Boxes to allow a clean state before and after Knight Rider Demo mode
      chk_led1.Checked:=false;
      chk_led2.Checked:=false;
      chk_led3.Checked:=false;
      chk_led4.Checked:=false;
      chk_led5.Checked:=false;


// Here begins the rough mode of Knight Rider Demo ;)

        comport1.WriteStr('1');
        Sleep(50);
        comport1.WriteStr('A');
        Sleep(50);
        comport1.WriteStr('2');
        Sleep(50);
        comport1.WriteStr('B');
        Sleep(50);
        comport1.WriteStr('3');
        Sleep(50);
        comport1.WriteStr('C');
        Sleep(50);
        comport1.WriteStr('4');
        Sleep(50);
        comport1.WriteStr('D');
        Sleep(50);
        comport1.WriteStr('5');
        Sleep(50);
        comport1.WriteStr('E');
        Sleep(50);

        comport1.WriteStr('4');
        Sleep(50);
        comport1.WriteStr('D');
        Sleep(50);
        comport1.WriteStr('3');
        Sleep(50);
        comport1.WriteStr('C');
        Sleep(50);
        comport1.WriteStr('2');
        Sleep(50);
        comport1.WriteStr('B');
        Sleep(50);
        comport1.WriteStr('1');
        Sleep(50);
        comport1.WriteStr('A');
        Sleep(50);
end;

end.






Manejar archivos DICOM













DICOM (Digital Imaging and Communication in Medicine) es el estándar
reconocido mundialmente para el intercambio de imágenes médicas, pensado
para el manejo, almacenamiento, impresión y transmisión de imágenes médicas.






Mas abajo pueden descargarse un conversor de archivos
en formato DICOM a bmp, jpg o png y un visor de imágenes que
incluye el objeto ActiveX ezDICOMax.ocx.










Para instalarlo:




Desde Delphi seleccionar 'Import ActiveX Control' desde el
menú "component" y después pulsar "Add" y
"Install" seleccionado el archivo DCMaxPro.OCX que está incluido en
la carpeta.




Una vez que se ha instalado correctamente se debería ver el
componente "DCMax" en la pestaña "ActiveX" de la barra de
componentes.









Si da un error del tipo "eOlesyserror" es porque no
se ha registrado el activex llamado ezDICOMax.ocx




Para instalarlo teclear:    c:\regsvr32 ezDICOMax.ocx




y para desinstalarlo  c:\regsvr32   /u   ezDICOMax.ocx 

 



Codigo fuente en Delphi :




Conversor de imagenes DICOM a bmp,jpg,png



Autor:  Wolfgang Krug and Chris Rorden

chris.rorden@nottingham.ac.uk





Visor de imagenes



PROCEDIMIENTOS DEL PROGRAMA


procedure TForm1.ToolClick(Sender: TObject);
begin
     DCMax1.DCMtool := (sender as TSpeedButton).tag;
end;

procedure TForm1.Exit1Click(Sender: TObject);
begin
  Close;
end;

procedure TForm1.Open1Click(Sender: TObject);
begin
     if not OpenDialog1.execute then exit;
     DCMax1.DCMfilename := OpenDialog1.Filename;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  DCMax1.DCMtoolbar := false;
  Smooth1.Checked := DCMax1.DCMsmoothOn;
end;

procedure TForm1.N2001Click(Sender: TObject);
var lPct: integer;
begin
     (Sender as TMenuItem).Checked := true;
     lPct := (Sender as TMenuItem).tag;
     if lPct = 0 then begin
         if not DCMax1.DCMbestFitZoom then
            DCMax1.DCMbestFitZoom := true;
     end else begin
         if DCMax1.DCMbestFitZoom then
            DCMax1.DCMbestFitZoom := false;
         DCMax1.DCMzoomPct := lPct;
     end;

end;

procedure TForm1.Smooth1Click(Sender: TObject);
begin
  Smooth1.Checked := not Smooth1.Checked;
  DCMax1.DCMsmoothOn := Smooth1.Checked;
end;

procedure TForm1.InvertedHotmetal1Click(Sender: TObject);
begin
     (Sender as TMenuItem).Checked := true;
     DCMax1.DCMcolorscheme := (Sender as TMenuItem).tag;
end;

procedure TForm1.N3x3Click(Sender: TObject);
var lMosaic: integer;
begin
    lMosaic := (Sender as TMenuItem).tag;
    (Sender as TMenuItem).checked := true;
    //Form1.caption := inttostr(lMosaic);
    DCMax1.DCMmosaicFirstSlice := 1;
    DCMax1.DCMmosaicLastSlice := maxint;
    DCMax1.DCMmosaicRows := lMosaic;
    DCMax1.DCMmosaicCols := lMosaic;

    //DCMax1.DCMmosaicX[lMosaic,lMosaic,1] := MaxInt;
    //DCMax1.DCMmosaicX[2,2,1,16];
    //xxxx
end;

procedure TForm1.DelphiDemo1Click(Sender: TObject);
begin
 showmessage('DelphiDemo by Chris Rorden. Demonstrates ezDICOM ActiveX component. '+
  DCMax1.DCMversionInfo);
end;

procedure TForm1.ShowHeader1Click(Sender: TObject);
begin
  ShowHeader1.Checked := not ShowHeader1.Checked;
  DCMax1.DCMshowHeader := ShowHeader1.Checked;
end;

procedure TForm1.Copy1Click(Sender: TObject);
begin
  if DCMax1.DCMshowHeader then
    DCMax1.DCMcopyHeader2Clipboard
  else
    DCMax1.DCMcopyImage2Clipboard;
end;

procedure TForm1.Saveimage1Click(Sender: TObject);
begin
     if not SaveDialog1.Execute then exit;
     DCMax1.DCMsaveToFile := SaveDialog1.FileName;
end;

procedure TForm1.Border1Click(Sender: TObject);
begin
 // DCMax1.DCMmo
end;

procedure TForm1.Unloadimages1Click(Sender: TObject);
begin
end;
(*procedure TForm1.Loadc0020dcm50times1Click(Sender: TObject);
var lInc: integer;
begin
  for lInc := 1 to 50 do
    DCMax1.DCMfilename := 'C:\0020.dcm';
end;

procedure TForm1.Unloadimages1Click(Sender: TObject);
begin
  DCMax1.DCMunloadImages:= 0;
end;
*)
procedure TForm1.PreviousSliceItemClick(Sender: TObject);
begin
  if DCMax1.DCMslice > 1 then
    DCMax1.DCMslice := DCMax1.DCMslice -1
  else
    DCMax1.DCMslice := DCMax1.DCMimageSlices;
end;

procedure TForm1.NextSliceItemClick(Sender: TObject);
begin
  if DCMax1.DCMslice < DCMax1.DCMimageSlices then
    DCMax1.DCMslice := DCMax1.DCMslice +1
  else
    DCMax1.DCMslice := 1;
end;

procedure TForm1.DCMax1DCMmouseMoveIntensity(ASender: TObject; X, Y,
  Button, Shift, Intensity: Integer; RGB: WordBool);
begin
  Caption := inttostr(X)+','+inttostr(Y)+':'+inttostr(intensity);
end;


















Morphing con Delphi











Espectacular programa de morphing basado en las transformaciones sucesivas de cuadriláteros, merece la pena que lo probéis ya que seguro que aprenderéis muchas cosas sobre esta técnica de imagen.



Autor:

Nicoo   (bigbezus@free.fr)

Codigo fuente


Descargar programa



Mini visor del registro







Muestra los items del registro de nuestro PC ( regedit.exe ) utilizando dos componentes: tTreeView y tListView.

Es lo que veríamos si vamos al botón de inicio->ejecutar y escribimos "regedit.exe"



Codigo fuente




Mostrar una regla en pantalla











Regla configurable en pantalla con las siguientes características:


  • Medida en pixels

  • Media en milímetros

  • Transparencia configurable

  • Tickers horizontales y verticales


etc..



http://delphi.about.com/library/weekly/aa080205a.htm

by Zarko Gajic

Codigo fuente










Modos blend


A continuación tienen una descripción de diferentes modos blend.



Los parámetros a y b son bytes (desde 0 a 255) debido a que las imágenes son almacenadas de esta forma. El valor devuelto es 1 byte. Recordar que para imágenes RGB se necesita procesar el color de cada canal.




por ejemplo si ponemos:

result := (a * b) SHR 8;

si la imagen es RGB habría que hacer


result.red := (a.red * b.red) SHR 8;

result.green := (a.green * b.green) SHR 8;

result.blue := (a.blue * b.blue) SHR 8;



Relación de modos:



Media





result := (a+b) SHR 1;










Multiplicador:


result := (a*b) SHR 8;





Screen:


result := 255 - ((255-a) * (255-b) SHR 8);





Oscuridad:


if a < b then

  result := a

else

  result := b;





Luminosidad:


if a > b then

  result := a

else

  result := b;





Diferencial:


result := abs(a-b);





Overlay:


if a < 128 then

  result := (a*b) SHR 7

else

  result := 255 - ((255-a) * (255-b) SHR 7);





Hard Light:


if b < 128 then

  result := (a*b) SHR 7

else

  result := 255 - ((255-b) * (255-a) SHR 7);





Soft light:


if b < 128 then

  result := a - (128-b) * (16384-sqr(128-a)) SHR 15

else

  result := ???;





Dodge:


if b = 255 then

  result := 255

else begin

  c := (a SHL 8) DIV (255-b);

  if c > 255 then result := 255 else result := c;

end;





Color Burn:


if b = 0 then

  result := 0

else begin

  c := 255 - (((255-a) SHL 8) DIV b);

  if c < 0 then result := 0 else result := c;

end;





Inverse color burn:


if a = 0 then

  result := 0

else begin

  c := 255 - (((255-b) SHL 8) DIV a);

  if c < 0 then result := 0 else result := c;

end;





Soft burn:


if a+b < 256 then begin

  if a = 255 then

    Result := 255

  else begin

    c := (b SHL 7) DIV (255-a);

    if c > 255 then Result := 255 else Result := c;

  end;

end

else begin

  // b cannot be zero here

  c := 255-(((255-a) SHL 7) DIV b);

  if c < 0 then Result := 0 else Result := c;

end;





Quadratic:


if b = 255 then

  result := 255

else begin

  c := a*a DIV (255-b);

  if c > 255 then result := 255 else result := c;

end;





Additive:


c := a+b;

if c > 255 then result := 255 else result := c;





Subtractive:


c := a+b-256;

if c < 0 then result := 0 else result := c;





Stamp:


c := a + 2*b - 256;

if c < 0 then

  result := 0

else if c > 255 then

  result := 255

else

  result := c;





Interpolación:


// for i := 0 to 255 do CosineTab[i] := Round(64-Cos(i*Pi/255)*64);

c := CosineTab[b] + CosineTab[a];

if c > 255 then result := 255 else result := c;





Opacidad o transparencia:

Se introduce el factor de opacidad variable llamado "o"



Definición de opacidad y transparencia:

fopacidad(a,b,o) = o * f(a,b) + (1 - o) * a

Transparencia t = (1 - o), so

ftransparencia(a,b,t) = (1 - t) * f(a,b) + t * a



La función será:
result := a + (f(a,b)-a) * o;
























Delphi Chromium Embedded Framework

Para los que quieran tener embebido en su aplicación un navegador que encapsula a Chrome y que además es compatible con Firemonkey (con alguna particularidad) aquí se lo pueden descargar:


Clic aqui para descargar




Una vez que se ha descargado hay que instalar el componente cefcomponent.dpk de la carpeta src (No olvidar poner la ruta de la carpeta "src" en Opciones-Library) 

Espero que este componente no tenga el memory leak que observé en el TWebBrowser.







Las nuevas funciones que ofrece son:

-Embebe un web browser con html5/css3

-parsing javascript

-html5 drag&drop

-Soporte para geolocalizacion

-Aceleracion por GPU

-Manejo de la configuracion para proxy

-Clases para utilizarlo en linea de comandos, url, xml y zip para lectura / parsing

-Acceso a las cookies

-Menu contextual 

-Acceso directo a DOM

-Notificacion e interceptacion de pulsaciones de teclas y foco de la aplicacion

-Manejo de zoom

-Manejo de descargas

-Soporte para webrequest -

-Soporte para multi_threaded_message_loop

-Puede trabajar sin el VCL o como un componente



Ejemplos:

Cargar una URL: (siendo crm: TChromium)

      crm.Browser.MainFrame.LoadUrl(edAddress.Text); 



Recargar una URL:

  if crm.Browser <> nil then
    if FLoading then
      crm.Browser.StopLoad else
      crm.Browser.Reload;




Hacer Zoom:

crm.Browser.ZoomLevel := crm.Browser.ZoomLevel + 0.5;



Obtener el codigo de la pagina:

var
  frame: ICefFrame;
  source: ustring;
begin
  if crm.Browser = nil then Exit;
  frame := crm.Browser.MainFrame;
  source := frame.Source;
  source := StringReplace(source, '<', '<', [rfReplaceAll]);
  source := StringReplace(source, '>', '>', [rfReplaceAll]);
  source := 'Source:
' + source + '

';
  frame.LoadString(source, 'http://tests/getsource');
end;




Ejecutar javascript:

    crm.Browser.MainFrame.ExecuteJavaScript(
      'alert(''JavaScript execute works!'');', 'about:blank', 0);




Mostrar herramientas del programador:

crm.Browser.ShowDevTools;



Ejecutar DOM:

begin
{$IFDEF DELPHI12_UP}
  crm.Browser.MainFrame.VisitDomProc(
    procedure (const doc: ICefDomDocument) begin
      doc.Body.AddEventListenerProc('mouseover', True,
        procedure (const event: ICefDomEvent) begin
          caption := getpath(event.Target);
        end)
  end);
{$ELSE}
  crm.Browser.MainFrame.VisitDomProc(domvisitorcallback);
{$ENDIF}
end;




Imprimir una pagina:

crm.Browser.MainFrame.Print;










Links para resolucion de problemas en Delphi

Navegando por la red he encontrado este trabajado post con links donde acudir para resolver problemas de programación.



Fuente:

https://anmiguel.wordpress.com/2012/02/02/lenguaje-delphi-y-resolucion-de-problemas/





Relación de links:






























































































Simulación del movimiento de los electrones en un campo electrico

Espectacular simulación realizada con OpenGL del movimiento de los electrones cuando atraviesan un campo eléctrico. Como muestra la image...