Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #2  
Antiguo 02-02-2007
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Poder: 26
seoane Va por buen camino
Se me ocurren un par de formas de hacerlo.

Una es consultando la entrada del registro:
Código:
HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM
Es decir:
Código Delphi [-]
uses Registry;

procedure GetPortList(List: TStringList);
var
  i: integer;
begin
  List.Clear;
  with TRegistry.Create do
  try
    RootKey:= HKEY_LOCAL_MACHINE;
    Access:= KEY_READ;
    if OpenKey('HARDWARE\DEVICEMAP\SERIALCOMM',FALSE) then
    begin
      GetValueNames(List);
      for i:= List.Count - 1 downto 0 do
        List[i]:= ReadString(List[i]);
      CloseKey;
    end;
  finally
    Free;
  end;
end;


// Por ejemplo para mostrarlo en un combobox
var
  List: TStringList;
begin
  List:= TStringList.Create;
  try
    GetPortList(List);
    // El Combobox se llama Combobox1
    Combobox1.Items.Assign(List);
  finally
    List.Free;
  end;
end;

Ahora sería interesante saber si el puerto esta ocupado:
Código Delphi [-]
function Ocupado(Puerto: String): Boolean;
var
  Handle: THandle;
begin
  Handle:= CreateFile(PChar('\\.\' + Puerto),GENERIC_READ or GENERIC_WRITE,0,
    nil,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0);
  if Handle <> INVALID_HANDLE_VALUE then
  begin
    CloseHandle(Handle);
    Result:= FALSE;
  end else
    Result:= TRUE;
end;

// Siguiendo el ejemplo anterior, solo mostramos los libres
var
  List: TStringList;
  i: integer;
begin
  List:= TStringList.Create;
  try
    GetPortList(List);
    Combobox1.Items.Clear;
    for i:= 0 to List.Count - 1 do
      if not Ocupado(List[i]) then
        Combobox1.Items.Add(List[i]);
  finally
    List.Free;
  end;
end;

Pero ya que tenemos una función que nos dice si un puerto esta disponible, por que no la usamos también para listar los puertos. Solo tenemos que comprobar un numero razonable de puertos, aquí uso 10 pero si lo crees necesario usa 100.
Código Delphi [-]
// Otra vez el mismo Combobox
var
  i: integer;
begin
  Combobox1.Clear;
  for i:= 0 to 10 do
    if not Ocupado('COM' + IntToStr(i)) then
      Combobox1.Items.Add('COM' + IntToStr(i));
end;
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Que archivos libres usar brandolin Conexión con bases de datos 18 15-12-2006 13:29:18
Sacar habitaciones libres por dia - Problema consulta SQL- VRO Firebird e Interbase 0 01-09-2005 11:12:22
Como detectar los puertos libres en un máquina JDNA Internet 1 08-05-2004 06:07:55
Puertos Serie mrmanuel Varios 9 05-03-2004 04:04:48
Puertos USB tarco35 Varios 0 25-10-2003 18:30:46


La franja horaria es GMT +2. Ahora son las 09:18:14.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi