title: Unknown reason for AV inside a procedure
body: <p>I created an empty unit to store my public procedures and functions but I get access violation in the first line of a procedure, but this for the first time only I call this procedure, later calls work normally !!</p>
  
  <p>The unit code:</p>
  
  <pre><code>unit myFunc;
  
  interface
  
  uses
    Windows, Messages, SysUtils, System.UITypes, Variants, Classes, Graphics, Controls, Forms;
  
    Procedure GSet(grid_form: TForm; app, operation: string);
  
  implementation
  
  Procedure GSet(grid_form: TForm; app, operation: string);
  var
  grd_idx: integer;
  begin
    if operation = 'save' then begin  // Access violation in this line 
  
      if (grid_form.components[grd_idx] is TMyComponent) then
      (grid_form.components[grd_idx] as TMyComponent).Storedata('c:\'+app);
    end;
  end;
  </code></pre>
  
  <p><strong>Update:</strong>
  I call this procedure from form create event like this</p>
  
  <pre><code>GridSettings(myform, 'cost', 'save');
  </code></pre>