Zitat:
Delphi-Quellcode:
function BaseCloseHandle(
Handle : TBaseHandle) : Boolean;
stdcall;
begin
if Handles[
Handle] =
nil then Result := false
else begin case Handles[
Handle]^.HandleType
of // Besonders diese Zeile.
bhtObject : Handles[
Handle]^.ObjectPointer.Free;
bhtWindowsHandle : Windows.CloseHandle(Handles[
Handle]^.Handle);
bhtCallback : Handles[
Handle]^.Callback();
end;
FreeMem(Handles[
Handle], SizeOf(TBaseHandleData));
Handles[
Handle] :=
nil;
Result := true;
end;
end;
bei gleichen/ähnlichen Gruppen rücke ich es mir gern mal übersichtlicher ein
Delphi-Quellcode:
// Handles[Handle].xyz // hier muß man nicht dereferenieren ... Delphi bemeckert das sogar
Function BaseCloseHandle(
Handle: TBaseHandle): Boolean;
StdCall;
Begin
If Handles[
Handle] <>
nil Then Begin
Case Handles[
Handle].HandleType
of
bhtObject: Handles[
Handle].ObjectPointer.Free;
bhtWindowsHandle: Windows.CloseHandle(Handles[
Handle].Handle);
bhtCallback: Handles[
Handle].Callback;
End;
FreeMem(Handles[
Handle], SizeOf(TBaseHandleData));
Handles[
Handle] :=
nil;
Result := True;
End Else Result := False;
End;
// oder
Function BaseCloseHandle(
Handle: TBaseHandle): Boolean;
StdCall;
Begin
Result := Handles[
Handle] <>
nil;
If Result
Then Begin
Case Handles[
Handle].HandleType
of
bhtObject: Handles[
Handle].ObjectPointer.Free;
bhtWindowsHandle: Windows.CloseHandle(Handles[
Handle].Handle);
bhtCallback: Handles[
Handle].Callback;
End;
FreeMem(Handles[
Handle], SizeOf(TBaseHandleData));
Handles[
Handle] :=
nil;
End;
End;