Re: Help on using this USB component

Posted by webmaster Guido on April 05, 2005

In Reply to: Help on using this USB component posted by Caramia p12316 on April 05, 2005

: I discoverd on Torry's this component:
: htp://www.swissdelphicenter.ch/torry/showcode.php?id=2211

: but i have no idea how i can use it. I tried to install (Component/InstallComponent... NewPackage). All was ok and the new package is now added to all other packages, LibraryPath has been updated but:

: 1. no component was added to palette.

: 2. I don't understand how to use it and how to built it inside my program. What function/procedure resturns information about the USB port?
---------------------

1. Your component does not appear on the Delphi components palette:

The code for "registering" the component and placing it on the components palette is missing. You have to add the following code to the .PAS unit, to register the new component and put it (for example) on the "Samples" page the palette:

unit U_USB;
interface
type
  ...                 
procedure Register;   { add this in the interface section }

implementation
  ...                 { existing component implementation }

procedure Register;   { add this in the implementation section }
begin
  RegisterComponents('Samples', [TComponentUSB]);
end;
  
end. 

Next, remove the component and install it again. Now, it should appear on the component palette, so that you can drop it on a form of your application.

2. Which procedure/function to use?

The component does not tell you IF a device is connected, but WHEN it is connected or removed.

In other words, there is no routine that tells you if some device is connected, but "events" are generated at the moment of connection and removal of a device.

Your program is "notified" of these events, if you create event handlers in the Object Inspector for the OnUSBArrival and/or OnUSBRemove events, and complete these code skeletons in the Code Editor (for example, show a message box that says "A new USB device was connected").

Please, let us know if it worked :)
Regards, Guido

 

Related Articles and Replies