TVirtualTable LoadFromFile preventing structure from beeing

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mxwx
Posts: 25
Joined: Mon 14 Nov 2005 08:22

TVirtualTable LoadFromFile preventing structure from beeing

Post by mxwx » Mon 16 Nov 2009 17:34

Hi,

I am using code like the following when setting data to a record of a tvirtualtable:

VTTest.Clear; //remove old data
VTTest.Edit;
VTTestI_FIELD1.AsInteger := 100; // dummy kto#
VTTestC_FIELD2.Value := '100'; // dummy kto#
VTTest.Post;

somewhat later I do:

fname := ExtractFileDir(Application.ExeName) + '\Data2.xml';
if FileExists(fname) then VTTest.LoadFromFile(fname);

when I repeat now

VTTest.Clear;
VTTest.Edit;
VTTestI_FIELD1.AsInteger := 100; // dummy kto#
VTTestC_FIELD2.Value := '100'; // dummy kto#
VTTest.Post;

I get an exception in the line after setting editmode maybe because the fielddefs have changed. In fact they are the same (at least similar) as bevor .loadfromfile as the xml which I use in the IDE and while running the programm are nearly the same. They differ solely in data1.xml has no data in it but the data2.xml has. Fielddefs are the same in both xml-files.

My question is. Is it like I think it is :-) and what can I do to simply push data to the record without destroing/recreating the structure. I have tried to solely load the data part of the xml-file but that is not working, or at least I don't know how. As it is more than 80 fields to fill up I would like a solution where I can "load" data instead of coding it by hand.

Thanks in advance

Michael

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Tue 17 Nov 2009 09:51

You can create TFileStream for your file and use the LoadFromStream method of TVirtualTable. This method has additional parameter LoadFields. Pass False for this parameter to preserve old fields.

mxwx
Posts: 25
Joined: Mon 14 Nov 2005 08:22

Post by mxwx » Wed 18 Nov 2009 15:09

Thanks, that worked :)

Post Reply