I really dont know much about delphi, especially string conversions, so sorry if i sound ignorant here. I am trying to make a package with an old delphi twain.pas, which is attached below. Anyway, there are 2 filename string declares listed:

I have tried casting to setup.Filename to PAnsiChar but it doesnt work.

The code was clearly written for a pre-Unicode version of Delphi, it will not work as-is in a Unicode version. You are going to have to make some tweaks to the code to re-Ansify it without having to re-write it for Unicode.

You cannot simply type-cast a WideChar array to a PAnsiChar pointer (well, you can, but it won't do what you are expecting). Change the array declaration to use 'AnsiChar' instead of 'Char'.

You will likely have to do the same thing for the TW_STR... type declarations as well.

You also need to change the 'ptr' variable in TOopsTwain.FileTransfer() from 'PChar' to either 'PByte' or 'PAnsiChar' (I would suggest 'PByte'), since it is being used in pointer arithmetic for a binary data buffer, not a text string.