Have a procedure which looks like
Procedure TestProc(TVar1, TVar2 : variant);
Begin
TVar1 := CreateOleObject('Excel.Application');
TVar1.Workbooks.open('C:\Test\Test.xls');
TVar1.Workbooks[1].Worksheets[1].Name := 'Sheet_1';
TVar2 := TVar1.Workbooks[1].Worksheets['Sheet_1'];
End;
Note: TVar1 and TVar2 are global variables
Calling the procedure in an onclick event of a button and then using the created objects is not working
Is it that delphi does not allow creation of procedures having variant parameters???
In the code sample you present,
TVar1andTVar2are not global variables, they are local parameters. They are not marked asvarparams, so they will receive a copy of whatever parameter values are passed into the function call, and any changes made to these local variables will not be passed back to the caller. It doesn’t matter if there are also global variables namedTVar1andTVar2declared elsewhere, in this procedure the local params will take precedence.If you want to pass modifications back to the caller, declare the parameters as
varparameters.