On 30 Jun 2012, at 16:34, Sven Barth wrote: > procedure TTest.CopyFile(aSrc, aDest: JIFile); > var > outstr: JIFileOutputStream; > instr: JIFileInputStream; > outchannel, inchannel: JNCFileChannel; > begin > outstr := JIFileOutputStream.Create(aDest); > instr := JIFileInputStream.Create(aSrc); > > try > inchannel := instr.getChannel; > outchannel := outstr.getChannel; > inchannel.transferTo(0, inchannel.size, outchannel as > JNCWritableByteChannel); > finally > try > if Assigned(inchannel) then > inchannel.close; > finally > if Assigned(outchannel) then > outchannel.close; > end; > end; > end;
The problem is that Android (and the JVM) assume that it's possible that an exception occurs inside instr.getChannel. In that case, inchannel will not be initialized inside the finally block, and you're not allowed to use any potentially uninitialized data. So you have to explicitly set inchannel and outchannel to nil before the first try-block. Jonas_______________________________________________ fpc-devel maillist - [email protected] http://lists.freepascal.org/mailman/listinfo/fpc-devel
