Perry Kappetein wrote:
> I was hoping if someone knows something about Virtual Tree.
>
> When I load my records it's putting it on the screen one by one,
> I used to have a for next loop where it was loading al the records, but was
> taking 7-10 seconds to load, while it suppose to be instantly
>
> this is what it is now, and hope somebody could help me.
For every node in the tree, you're issuing a separate SQL query. I'd
certainly expect that to be slow.
> TdsmainForm = class(TForm)
> vtree: TVirtualStringTree;
> RomDatabase: TABSDatabase;
> ABSQuery1: TABSQuery;
> ABSQuery2: TABSQuery;
> ABSroms: TABSTable;
> Button1: TButton;
> Button2: TButton;
>
>
> procedure FormCreate(Sender: TObject);
> procedure vtreeGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
> Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
> procedure Button1Click(Sender: TObject);
> procedure Button2Click(Sender: TObject);
> procedure vtreeInitNode(Sender: TBaseVirtualTree; ParentNode,
> Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
Make sure you also handle the OnFreeNode event. Otherwise, you'll have
memory leaks since the string fields of your node data won't get cleared.
> private
> { Private declarations }
> public
> { Public declarations }
>
>
> { Public declarations }
>
> Node: PVirtualNode;
> Data: PTreeData;
Why are these declared as public fields of the class? They should be
local variables. If some code outside the class needs to know which node
or data to work on, pass it as an argument to that specific code. A
public field of a global variable is just as bad as a global variable.
> procedure TdsmainForm.vtreeInitNode(Sender: TBaseVirtualTree; ParentNode,
> Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
> var
> tst : string;
> i : integer;
> begin
>
> tst:='SELECT roms.* ,pic.* FROM roms LEFT JOIN pic ON roms.romnumber =
> pic.romnumber where roms.romnumber="'+inttostr(Node.Index)+'" ORDER by
> romnumber ASC';
> absquery1.SQL.Text := tst;
> absquery1.open ;
> if absquery1.RecordCount <> 0 then
If you just need to know whether you got at least one result, then isn't
that what the Eof method is for?
--
Rob