Project JEDI - Issue Tracker
Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0003770 [JEDI VCL] 00 JVCL Components crash always 2006-06-21 04:27 2006-07-29 07:57
Reporter ibdm-c View Status public  
Assigned To obones
Priority normal Resolution fixed  
Status resolved   Product Version 3.20
Summary 0003770: TJvInspectorPropData.New / NewByNames crash if parameter AInstance does not inherit from TPersistent
Description If you call the class functions TJvInspectorPropData.New or TJvInspectorPropData.NewByNames with a parameter AInstance that does not inherit from TPersistent, the function crashes. This is due to the fact, that an object that does not inherit from TPersistent has no ClassInfo. In that case the ClassInfo is nil!
Unfortunately you will have to know about that, because you will get no "speaking" error message.
  
Additional Information Here's my bugfix for this:


(1) add a new resourcestring in JvResources.pas:

//=== JvInspector.pas ========================================================
resourcestring
   ...
  RsEJvInspDataNoPersistentClass = '%s is does not inherit from TPersistent';


(2) modify TJvInspectorPropData.New and TJvInspectorPropData.NewByNames in
JvInspector.pas:

class function TJvInspectorPropData.New(const AParent: TJvCustomInspectorItem;
  const AInstance: TObject; const TypeKinds: TTypeKinds): TJvInspectorItemInstances;
var
  PropCount: Integer;
  PropList: PPropList;
begin
  SetLength(Result, 0);
  if (AInstance.ClassInfo <> nil) then
  begin
    PropCount := GetPropList(AInstance.ClassInfo, TypeKinds, nil);
    GetMem(PropList, PropCount * SizeOf(PPropInfo));
    try
      GetPropList(AInstance.ClassInfo, TypeKinds, PropList);
      Result := New(AParent, AInstance, PropList, PropCount); // Generate Items for each Property element.
    finally
      FreeMem(PropList);
    end;
  end
  else
    raise EJvInspectorData.CreateResFmt(@RsEJvInspDataNoPersistentClass, [AInstance.ClassName]);
end;

class function TJvInspectorPropData.NewByNames(const AParent: TJvCustomInspectorItem;
  const AInstance: TObject; const NameList: array of string;
  const ExcludeList: Boolean; const TypeKinds: TTypeKinds): TJvInspectorItemInstances;
var
  PropCount: Integer;
  PropList: PPropList;
  I: Integer;
  PropInfo: PPropInfo;
  NameIdx: Integer;
begin
  SetLength(Result, 0);
  if (AInstance.ClassInfo <> nil) then
  begin
    PropCount := GetPropList(AInstance.ClassInfo, TypeKinds, nil);
    GetMem(PropList, PropCount * SizeOf(PPropInfo));
    try
      GetPropList(AInstance.ClassInfo, TypeKinds, PropList);
      for I := 0 to Pred(PropCount) do
      begin
        PropInfo := PropList[I];
        NameIdx := High(NameList);
        while (NameIdx >= 0) and not AnsiSameText(NameList[NameIdx], PropInfo.Name) do
          Dec(NameIdx);
        if ((NameIdx < 0) and ExcludeList) or ((NameIdx > -1) and not ExcludeList) then
        begin
          SetLength(Result, Length(Result) + 1);
          Result[High(Result)] := New(AParent, AInstance, PropInfo);
        end;
      end;
    finally
      FreeMem(PropList);
    end;
  end
  else
    raise EJvInspectorData.CreateResFmt(@RsEJvInspDataNoPersistentClass, [AInstance.ClassName]);
end;
Tags No tags attached.
Attached Files

- Relationships

-  Notes
(0009618)
obones (administrator)
2006-06-22 08:02

You could also set the M+ set on the class, and while it does not derive from TPersistent, you would get the ClassInfo.
Hence the fact that I'm not sure this is required nor desirable to force it to derive from Tpersistent. However, having a message saying that no class info could be found would be better than a crash.
(0009622)
ibdm-c (reporter)
2006-06-22 08:36

M+? Ahh, you mean the compiler directive. Yes, of course you're right!

{$M+}
  TMyClass = class(TObject)
    ..
  end;
{$M-}

or

{$TYPEINFO ON}
  TMyClass = class(TObject)
    ..
  end;
{$TYPEINFO OFF}

solves the problem too / makes it not necessary to derive from TPersistent.
But a little reminder "derive class from TPersistent or switch on the generation of typeinfo for the class declaration" would be nice.

- Issue History
Date Modified Username Field Change
2006-06-21 04:27 ibdm-c New Issue
2006-06-22 08:02 obones Note Added: 0009618
2006-06-22 08:02 obones Status new => feedback
2006-06-22 08:36 ibdm-c Note Added: 0009622
2006-07-29 07:57 obones Status feedback => resolved
2006-07-29 07:57 obones Fixed in Version => Daily / SVN
2006-07-29 07:57 obones Resolution open => fixed
2006-07-29 07:57 obones Assigned To => obones


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker