Be careful, the return value of the function you must control!

This two-day encounter problems, our FMX project, one of the functions on the windows operating normally, abnormally on Android.

Finally found, it turned out to be colleagues did not deal with the return value of a function caused.

function Test(aName:string):TObject;
var
  o:TObject;
begin
  ...
  if aName='123' then
  begin
     o:=TObject.Create;
     result:=o;
  end;
end;

Code is similar to the above, in Windows, when aName <> 123, the process returns nil, while in android, no returns nil. Amended as follows:

function Test(aName:string):TObject;
var
  o:TObject;
begin
  result:=nil;//修正.
  ...
  if aName='123' then
  begin
     o:=TObject.Create;
     result:=o;
  end;
end;

Daniel wrote the impression that there is written, must cultivate the habit of default handler return values. This time was a lesson in reality!

Guess you like

Origin www.cnblogs.com/kinglandsoft/p/12461701.html