Ver Mensaje Individual
  #4  
Antiguo 26-07-2007
Avatar de cHackAll
[cHackAll] cHackAll is offline
Baneado?
 
Registrado: oct 2006
Posts: 2.159
Reputación: 20
cHackAll Va por buen camino
Código Delphi [-]
function DelReg(Index: Cardinal): Boolean;
var hFile, Pos, Dummy: Cardinal; var Last: TRegistro;
begin
 hFile := CreateFile('archivo.dat', GENERIC_READ + GENERIC_WRITE, 0, nil, OPEN_EXISTING, 0, 0);
 Result := hFile <> INVALID_HANDLE_VALUE;
 if not Result then Exit;                                            // No se pudo acceder al archivo
 Result := Index < (GetFileSize(hFile, nil) div SizeOf(TRegistro));
 if not Result then                                                  // Registro fuera de rango
  begin
   CloseHandle(hFile);
   Exit;
  end;
 Pos := SetFilePointer(hFile, -SizeOf(Last), nil, FILE_END);         // Te vas al último registro
 ReadFile(hFile, Last, SizeOf(TRegistro), Dummy, nil);               // Lo lees
 SetFilePointer(hFile, Index * SizeOf(Last), nil, 0);                // Te vas al registro a eliminar
 WriteFile(hFile, Last, SizeOf(Last), Dummy, nil);                   // Lo pisas con el último
 SetFilePointer(hFile, Pos, nil, 0);                                 // Regresas al ultimo registro
 SetEndOfFile(hFile);                                                // Truncas el archivo en ésa posición
 CloseHandle(hFile);
end;

Decía "en delphi", luego ví "Código PHP" así que te lo dejo con pura API. Funciona si no interesa el orden de los registros.
Responder Con Cita