fix AV when retrieving object (from vincent)

git-svn-id: trunk@4921 -
This commit is contained in:
micha 2003-12-21 11:50:39 +00:00
parent 99e29f1635
commit ddfd56c757
2 changed files with 24 additions and 8 deletions

View File

@ -276,15 +276,21 @@ End;
{ TWin32CheckListBoxStrings }
constructor TWin32CheckListBoxStrings.Create(List : HWND; TheOwner: TWinControl);
begin
inherited Create(List, TheOwner);
with FDefaultItem do begin
Checked := false;
TheObject := nil;
end;
end;
function TWin32CheckListBoxStrings.GetChecked(const Index: Integer): Boolean;
var
Data: PWin32CheckListBoxItemRecord;
begin
Data := GetItemRecord(Index, false);
if Data <> nil then
Result := Data^.Checked
else
Result := false;
Result := Data^.Checked
end;
procedure TWin32CheckListBoxStrings.SetChecked(const Index: Integer;
@ -301,10 +307,12 @@ function TWin32CheckListBoxStrings.GetItemRecord(const Index: Integer;
const CreateNew: boolean): PWin32CheckListBoxItemRecord;
begin
Result := PWin32CheckListBoxItemRecord(Windows.SendMessage(FWin32List, LB_GETITEMDATA, Index, 0));
if (not Assigned(Result)) and CreateNew then begin
Result := new(PWin32CheckListBoxItemRecord);
Result^.Checked := false;
Result^.TheObject := nil;
if (not Assigned(Result)) then begin
if CreateNew then begin
Result := new(PWin32CheckListBoxItemRecord);
Result^ := FDefaultItem;
end
else Result := @FDefaultItem;
end;
end;
@ -527,6 +535,9 @@ End;
{ =============================================================================
$Log$
Revision 1.25 2003/12/21 11:50:39 micha
fix AV when retrieving object (from vincent)
Revision 1.24 2003/12/15 22:04:05 micha
nil check

View File

@ -68,6 +68,7 @@ Type
TWin32CheckListBoxStrings = class(TWin32ListStringList)
private
FDefaultItem: TWin32CheckListBoxItemRecord;
function GetChecked(const Index: Integer): Boolean;
procedure SetChecked(const Index: Integer; const AValue: Boolean);
function GetItemRecord(const Index: Integer; const CreateNew: boolean): PWin32CheckListBoxItemRecord;
@ -76,6 +77,7 @@ Type
function GetObject(Index: Integer): TObject; override;
procedure PutObject(Index: Integer; AObject: TObject); override;
public
constructor Create(List : HWND; TheOwner: TWinControl);
class procedure DeleteItemRecords(const List: HWND);
class procedure DeleteItemRecord(const List: HWND; const Index: integer);
procedure Clear; override;
@ -113,6 +115,9 @@ Type
{ =============================================================================
$Log$
Revision 1.13 2003/12/21 11:50:39 micha
fix AV when retrieving object (from vincent)
Revision 1.12 2003/12/15 21:57:16 micha
checklistbox, implement object+checked; from vincent