我有整数和字符串的类,当我使用整数时一切都很好但是当我使用字符串程序崩溃时
//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;
答案 0 :(得分:8)
不......不完全
k.catId:=4646; // <--- that crashing the program
k.catName:='777';
您可能包含的错误消息类似于
在模块“MyProject.exe”中的地址xxxxxxxx处访问冲突。读取地址xxxxxxxx。
此处k
是CatInfoType
的类 - 但您尚未实例化它。你想要的是:
k := CatInfoType.Create;
k.catId := 4646;
//... etc
答案 1 :(得分:2)
您无法实例化实例。这将通过
完成k := CatInfoType.Create(...);