EugeneK 27 Posted Tuesday at 04:08 PM Hi In OverbyteIcsWebSocketCli.pas there are many instances of this if Obj <> nil then Obj.Free; I think it should be simplified to just Obj.Free; Share this post Link to post
DelphiUdIT 256 Posted Tuesday at 05:08 PM Uhmm, I don't remember how FREE procedure is operational in the old versions of Delphi. If the FREE TObject procedure doesn't test the NIL before destroy it ... So for new Delphi version is OK, but for older you should see. 1 Share this post Link to post
Angus Robertson 658 Posted Tuesday at 05:30 PM ICS still supports Delphi 7. Angus Share this post Link to post
EugeneK 27 Posted Tuesday at 06:41 PM 1 hour ago, Angus Robertson said: ICS still supports Delphi 7. Angus Free on nil works in Delphi 7 as well. 1 Share this post Link to post
EugeneK 27 Posted Tuesday at 06:57 PM 1 hour ago, DelphiUdIT said: Uhmm, I don't remember how FREE procedure is operational in the old versions of Delphi. If the FREE TObject procedure doesn't test the NIL before destroy it ... So for new Delphi version is OK, but for older you should see. If you have license Delphi 7 is available for download on Embarcadero website, you can check source code there. Share this post Link to post
Anders Melander 2044 Posted Tuesday at 07:33 PM 2 hours ago, DelphiUdIT said: Uhmm, I don't remember how FREE procedure is operational in the old versions of Delphi. Delphi 1 ; procedure TObject.Free ObjectFree: MOV BX,SP LES DI,SS:[BX+4] MOV AX,ES OR AX,DI JE @@1 MOV AL,1 PUSH AX PUSH ES PUSH DI LES DI,ES:[DI] CALL ES:[DI].vtDestroy @@1: RETF 4 Delphi 2 procedure TObject.Free; asm TEST EAX,EAX JE @@exit MOV ECX,[EAX] MOV DL,1 CALL dword ptr [ECX].vtDestroy @@exit: end; 3 Share this post Link to post
EugeneK 27 Posted Tuesday at 09:01 PM According to https://stackoverflow.com/a/8591357/1325672 Quote The sole reason for introducing the non-virtual Free method on TObject, was for use in destructors as a simple shorthand for: if FField <> nil then FField.Destroy; Share this post Link to post
DelphiUdIT 256 Posted Tuesday at 11:08 PM @Eugene Kryukov My only concern was related to the scrupulousness of maintaining the compatibility with the past that ICS still maintains. I don't need proof or anything else. @Anders Melander I was referring to old versions, not ancient versions (I know you meant to point out that the nil test has existed since the first versions of Delphi) Share this post Link to post
KBazX 0 Posted Wednesday at 07:17 AM Lines from file "c:\Program Files (x86)\Borland\Delphi7\Source\Rtl\Sys\System.pas" procedure TObject.Free; begin if Self <> nil then Destroy; end; In theory, all this can be replaced with a more secure function FreeAndNil(Obj). Share this post Link to post
Angus Robertson 658 Posted Wednesday at 08:00 AM In general, ICS does use FreeAndNil for new code, if not nilled in code, the nil being the important part, since double Free without nil does cause an exception. Double free is common, due to the complex inheritance of many ICS components. But I simply don't have the time to clean up code written up to 25 years ago, unless I'm updating that code for other reasons. It all needs testing afterwards, and often correction when it then fails to compile on older versions of Delphi... Angus 2 Share this post Link to post