If you are running that code outside an workflow instance execution, then you must call SaveWorkflowInstance to persist changes to the workflow.
As I said, if the form was executed from the workflow, there is already an instance running. The code in SaveCreatedRecordIDinWFI create ANOTHER instance, saves it, but if the execution flow goes back to the original workflow instance, that is then saved, and overwrites all changes you made in SaveCreatedRecordIDinWFI method.
I don't know how your workflow works exactly, not sure how your form is being called, how is your script. But as I said, you just need to pass the workflow instance from script to your form/delphi code.
Here are the small fixes in your code to make it work:
I changed my code according to your instructions, but the variable "RecordIDCreated" is still not stored in the WFI.
Is your form being displayed as ShowModal?
Yes, the form that creates the document is shown as ShowModal.
FCreateDoc will call a procedure in Form1 to add a record for the created document.
If it helps I can sent you a project by mail.
Did you put a breakpoint in the wvar.Value assignment just to check if the variable is being found by the FindByName method?