Code: Alles auswählen
type
SANE_Word = LongInt;
SANE_Bool = SANE_Word;
SANE_Char = ^Char;
SANE_String_Const = SANE_Char;
type
SANE_Device = record
name : SANE_String_Const; // unique device name
vendor : SANE_String_Const; // device vendor string
model : SANE_String_Const; // device model name
dev_type : SANE_String_Const; // device type (e.g., "flatbed scanner")
end;
PSANE_Device = ^SANE_Device;
Device_List = array of PSANE_Device;
PDevice_List = ^Device_List;
type
function sane_init(version_code: PSANE_Int; authorize: SANE_Auth_Callback): SANE_Status; cdecl; external SaneExport;
procedure sane_exit; cdecl; external SaneExport;
function sane_get_devices(devices: PDevice_List; local_only: SANE_Bool): SANE_Status; cdecl; external SaneExport;
Code: Alles auswählen
// Initialisieren.
bIsLibInit := (sane_init(@iVersion, nil) = SANE_STATUS_GOOD);
Code: Alles auswählen
procedure TSaneScanner.SaneGetDeviceList;
{*******************************************************************************
* Die Liste der verfügbaren Scanner holen.
}
var
pdList : PDevice_List;
i : Integer;
begin
if bIsLibInit
then begin
try
WriteInfo(0, Format('LibSane Version: %s', [sVersion]));
WriteInfo(1, rsDevicesSearch);
i := 0;
pdList := nil;
SetLength(aScannerList, 0);
Getmem(pdlist, sizeof(pdlist));
LastStatus := sane_get_devices(pdlist, SANE_TRUE);
if (LastStatus = SANE_STATUS_GOOD) then
while (pdlist^[i] <> nil)
do begin
SetLength(aScannerList, i + 1);
aScannerList[i].name := pdlist^[i]^.name; // Name im System
aScannerList[i].vendor := pdlist^[i]^.vendor; // Hersteller
aScannerList[i].model := pdlist^[i]^.model; // Modellbezeichnung
aScannerList[i].dev_type := pdlist^[i]^.dev_type; // Bauart
Inc(i);
end;
finally
if (pdList <> nil)
then Freemem(pdList);
end;
end;
end;
Nun habe ich in die Procedure ein sane_exit und sane_init eingefügt.
Code: Alles auswählen
var
..
iVersion: SANE_Int;
begin
// Library schliessen
if bIsLibInit
then sane_exit;
// Neues Init
bIsLibInit := (sane_init(@iVersion, nil) = SANE_STATUS_GOOD);
..