Ver Mensaje Individual
  #1  
Antiguo 06-02-2007
mierda mierda is offline
Miembro
 
Registrado: may 2006
Posts: 129
Reputación: 19
mierda Va por buen camino
usar lockfile and unlockfile

Hola, estoy tratando de usar estas funciones de la api ... pero no me chutan ... a ver si me podeis echar algun cable ... ya que a esta profundidad me pierdo

Código Delphi [-]
unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    Button2: TButton;
    OpenDialog1: TOpenDialog;
    Button3: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
 hFile: THandle;
 Sof: Longint;
begin
try
 hFile := CreateFile(pchar(edit1.text),0,0,nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
 Sof := GetFileSize(hFile,nil);
 if UnlockFile(hFile,0,0,Sof,0) then
   showmessage ('Unlock CONSEGUIDO!!!!')
 else
   showmessage ('Unlock no conseguido');
 CloseHandle(hFile);
except
    showmessage ('Ha ocurrido un error al intentar hacer el unlock');
  end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenDialog1.Execute then
  edit1.Text := OpenDialog1.FileName;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
 hFile: THandle;
 Sof: Longint;
begin
try
 hFile := CreateFile(pchar(edit1.Text),0,0,nil, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
 Sof := GetFileSize(hFile,nil);
 if LockFile(hFile,0,0,Sof,0) then
   showmessage ('Lock CONSEGUIDO!!')
 else
   ShowMessage('Lock no conseguido');
Except
  showmessage ('Ha ocurrido un error al intentar hacer el lock')
  end;
end;
end.

muchas gracias.
Responder Con Cita