String 为什么程序在分配字符串后崩溃

String 为什么程序在分配字符串后崩溃,string,delphi,crash,String,Delphi,Crash,我有一个包含整数和字符串的类,当我使用整数时,一切都很好,但当我使用字符串时,程序崩溃了 //class CatInfoType = class(TRemotable) private FcatId: Integer; FcatName: string; FcatParent: Integer; FcatPosition: Integer; FcatIsProductCatalogueEnabled: Integer; published

我有一个包含整数和字符串的类,当我使用整数时,一切都很好,但当我使用字符串时,程序崩溃了

//class
CatInfoType = class(TRemotable)
  private
    FcatId: Integer;
    FcatName: string;
    FcatParent: Integer;
    FcatPosition: Integer;
    FcatIsProductCatalogueEnabled: Integer;
  published
    property catId : Integer read FcatId write FcatId;
    property catName : string read FcatName write FcatName;
    property catParent : Integer read FcatParent write FcatParent;
    property catPosition : Integer read FcatPosition write FcatPosition;
    property catIsProductCatalogueEnabled: Integer 
                                       read FcatIsProductCatalogueEnabled 
                                       write FcatIsProductCatalogueEnabled;
end;
//program code 
procedure TForm2.Button7Click(Sender: TObject);
var
  rc: Integer;
  k: CatInfoType;
  l:String;
begin
  k.catId:=4646;
  k.catName:='777';//that crashing the program
end;
不,不完全是

k.catId:=4646; //  <--- that crashing the program
k.catName:='777';

未能实例化实例。那就由我来做了

k := CatInfoType.Create(...);

整数的赋值可能会成功,但它可能会损坏内存。字符串赋值不太可能成功,因为当前值将最终确定。“这是可能的失败点。”我想这是可能的。我猜OP发现指令指针在中断后已增加到第二行,但我认为这是问题的原因。无论哪种方式…都不值得分析。没有创建对象,没有骰子。没什么好说的了。创建对象并继续前进!:-正在崩溃,程序崩溃不是问题描述。崩溃具体意味着什么?很明显,您遇到了访问冲突,但这些信息应该包括在您的问题中,以及您收到的确切错误消息中。事实上,在谷歌上搜索这个错误信息,你甚至不需要在这里提问就可以找到答案。
k := CatInfoType.Create(...);