#1 2011-11-15 15:34:39

Sir Rufo
Member
Registered: 2011-10-14
Posts: 24

TSQLRecord.FillFrom didn't copy Collections

Here a small sample project

unit View.Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes,
  Graphics, Controls, Forms, Dialogs, StdCtrls,
  SynCommons, SQLite3Commons;

type
  TMyItem = class( TCollectionItem )
  private
    fData : string;
  published
    property Data : string read fData write fData;
  end;

  TSQLTest = class( TSQLRecord )
  private
    fMyColl : TCollection;
  public
    constructor Create; override;
    destructor Destroy; override;
  published
    property MyColl : TCollection read fMyColl;
  end;

  TForm1 = class( TForm )
    Button1 : TButton;
    procedure Button1Click( Sender : TObject );
  private
  public
  end;

var
  Form1 : TForm1;

implementation

{$R *.dfm}
{ TSQLTest }

constructor TSQLTest.Create;
begin
  inherited;
  fMyColl := TCollection.Create( TMyItem );
end;

destructor TSQLTest.Destroy;
begin
  fMyColl.Free;
  inherited;
end;

procedure TForm1.Button1Click( Sender : TObject );
var
  RecSource, RecDest : TSQLTest;
begin
  RecDest := TSQLTest.Create;
  try

    RecSource := TSQLTest.Create;
    try
      with TMyItem( RecSource.MyColl.Add ) do
        begin
          Data := 'Have a nice day';
        end;

      ShowMessage( IntToStr( RecSource.MyColl.Count ) ); // <- Shows 1

      RecDest.FillFrom( RecSource );
    finally
      RecSource.Free;
    end;

    ShowMessage( IntToStr( RecDest.MyColl.Count ) ); // <- Access Violation!!

  finally
    RecDest.Free;
  end;
end;

end.

Offline

#2 2011-11-15 18:00:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,206
Website

Re: TSQLRecord.FillFrom didn't copy Collections

The special case of TCollection was not handled in this case.

I've added this as you expected.
See http://synopse.info/fossil/info/0f0bc73310

Thanks for the report.

Offline

#3 2011-11-15 19:29:22

Sir Rufo
Member
Registered: 2011-10-14
Posts: 24

Re: TSQLRecord.FillFrom didn't copy Collections

Thank u 4 the fix ... well done smile

Offline

Board footer

Powered by FluxBB