Home > Back-end > TServerMethods1Client object is released prompt invalid pointer operation error
TServerMethods1Client object is released prompt invalid pointer operation error
Time:10-12
Write a small program of DATASNAP propagation, prompt invalid when casting TServerMethods1Client object pointer operation error, to obtain each tall person to give directions, Procedure TForm12. ListView1Click (Sender: TObject); Const BufferSize=102400;//100 KB Var FStream: TFilestream; Stream: Tstream; BytesReadCount: Integer; Buffer: TBytes; Filename: the string; Cs: TServerMethods1Client; The begin If ListView1. ItemIndex=1 then the exit; Image1. Picture. Graphic:=nil; Cs:=TServerMethods1Client. Create (dm1. SQLConnection1. DBXConnection); Filename:='C: \ TEMP \ TEMP. JPG'; Then if SysUtils. FileExists (FileName) FStream:=TFilestream. Create (FileName, fmOpenWrite or fmShareDenyNone) The else fStream:=TFilestream. Create (FileName, fmCreate); Stream:=cs DownLoadFile (ClientDataSet2 FieldByName (' storage directory). AsString + ListView1. Items [ListView1. ItemIndex]. Caption); Try SetLength (Buffer, BufferSize); FStream. Position:=0; Repeat BytesReadCount:=stream. Read (Buffer [0], BufferSize); If BytesReadCount & gt; 0 then FStream. Write (Buffer [0], BytesReadCount); Until BytesReadCount & lt; BufferSize; The finally //cs. Destroy; //cs. Free;//this two statements indicate invalid pointer errors FStream. Free; Stream. Free; end; end;
CodePudding user response:
Free interior is invoked destroy (self & lt;> Nil)
CodePudding user response:
Don't Free CS, instead of CS:=nil;
CodePudding user response:
Do not safe, upstairs in a destructor function statement released child object, the object directly assigned to nil can lead to child objects take up memory leaks, with the most safe, free, I think the building Lord failure may be the cause of CS internal problem,,