unit uDataSetProvider;

interface

uses Rubies;

var
  cDataSetProvider: Tvalue;

procedure Init_DataSetProvider;

implementation

uses 
  SysUtils, Provider, DB, uDefUtils, Pythia, uDataSet, uRDB, uFieldDef, uIndexDef;

procedure DataSetProvider_setup(obj: Tvalue; real: TDataSetProvider);
begin
end;

//function DataSetProvider_new(argc: integer; argv: Pointer; This: Tvalue): Tvalue; cdecl;
//var
//  real: TDataSetProvider;
//begin
//  real := TDataSetProvider.Create(nil);
//  result := CompoAlloc(This, real);
//  DataSetProvider_setup(result, real);
//  rb_obj_call_init(result, argc, argv);
//end;

//////// new -> alloc + initialize

function DataSetProvider_alloc(klass: Tvalue): Tvalue; cdecl;
var
  real: TDataSetProvider;
begin
  real := TDataSetProvider.Create(nil);
  result := CompoAlloc(klass, real);
  DataSetProvider_setup(result, real);
end;

function DataSetProvider_initialize(argc: integer; argv: Pointer; This: Tvalue): Tvalue; cdecl;
var
  real: TDataSetProvider;
  v:Tvalue;
  p: Pvalue;
begin
  result := Qnil;
  if argc > 0 then begin
    p := argv;
    v := p^;
    real := ap_data_get_struct(This);
    real.DataSet := TDataSet(ap_data_get_struct(v));
    rb_iv_set(This, '@data_set', v);
  end
end;

procedure Init_DataSetProvider;
begin
  cDataSetProvider := DefinePersistentClass(mRDB, TDataSetProvider, ap_cComponent, nil);
  //DefineSingletonMethod(cDataSetProvider, 'new', DataSetProvider_new);
  rb_define_alloc_func( cDataSetProvider, DataSetProvider_alloc );
  rb_define_private_method( cDataSetProvider, 'initialize' , @DataSetProvider_initialize, -1 );
end;

end.
