Hallo,
ich beschäftige mich zur Zeit mit dem VirtualStringTree von M.Lischke.
Im Internet habe ich ein Beispiel gefunden, das ein ClientDataSet
als Verbindung zu einer Datenbank benutzt.
Ich versuche nun mit ADOConnection und BetterADODataSet eine
Verbindung zu einer Access Datenbank herzustellen.
Das Problem liegt in der Methode FindKey, die von ADO nicht
unterstützt wird. Mit SEEK habe ich es bereits versucht, bekomme aber nur leere Datensätze. IndexName habe ich gesetzt, CommandType=cmdTableDirect, CursorLocation=clUseServer und
CursorType=ctKeySet.
So funktionierts mit dem ClientDataSet (cds)
------------------------------------------------------
type
TBasicNode =
class
protected
FCaption : shortstring;
FID : longint;
FImageIndex : longint;
FHasChanged : boolean;
public
constructor Create( const sCaption : shortstring; const iID, iIndex: longint);
property Caption : shortstring read FCaption write FCaption;
property ID : longint read FID write FID;
property ImageIndex : longint read FImageIndex write FImageIndex;
property HasChanged : boolean read FHasChanged write FHasChanged;
end;
TBasicNodeAdd =
class(TBasicNode)
protected
FJobTitle : shortstring;
FAdd1 : shortstring;
FAdd2 : shortstring;
FAdd3 : shortstring;
public
property Add1 : shortstring read FAdd1 write FAdd1;
property Add2 : shortstring read FAdd2 write FAdd2;
property Add3 : shortstring read FAdd3 write FAdd3;
property JobTitle : shortstring read FJobTitle write FJobTitle;
end;
PTreeData = ^TTreeData;
TTreeData = record
FObject : TBasicNode;
end;
---------------------------------------------------
constructor TBasicNode.Create( const sCaption : shortstring; const iID, iIndex: longint);
begin
inherited Create;
FCaption := sCaption;
FID := iID;
FImageIndex := iIndex;
end;
const
FLDN_CustNo = 0;
FLDN_Company = 1;
FLDN_Addr1 = 2;
FLDN_Addr2 = 3;
FLDN_City = 4;
FLDN_State = 5;
FLDN_Zip = 6;
FLDN_Country = 7;
FLDN_Phone = 8;
FLDN_FAX = 9;
FLDN_TaxRate = 10;
FLDN_Contact = 11;
FLDN_LastInvoiceDate = 12;
---------------------------------------------------
procedure TfrmVTDBExample.VTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var Text: WideString);
var
Data : PTreeData;
FObject : TBasicNodeAdd;
iLevel : integer;
begin
Text := '';
Data := Sender.GetNodeData(Node);
if Assigned(Data) and (Data.FObject <> nil) then with Data.FObject do
begin
iLevel := Sender.GetNodeLevel( Node );
case Column of
0:
begin
case TextType of
ttNormal:
begin
if iLevel = 0 then
begin
Text:=Caption
end
else
begin
if cds.FindKey([ID]) then with cds do
Text := Trim( Fields[ FLDN_Addr1 ].AsString + ' ' +
Fields[ FLDN_Addr2 ].AsString + ' ' +
Fields[ FLDN_City ].AsString + ' ' +
Fields[ FLDN_State ].AsString + ' ' +
Fields[ FLDN_Zip ].AsString + ' ' +
Fields[ FLDN_Country ].AsString );
end;
end;
ttStatic:
begin
Text := '';
end;
end;
end;
1:
begin
FObject := TBasicNodeAdd( Data.FObject );
case TextType of
ttNormal:
begin
if (iLevel = 0)and cds.FindKey([ID])
then with cds do
Text := Fields[ FLDN_Contact ].AsString;
end;
end;
end;
2:
begin
if TextType = ttNormal then
Text := ' ';
end;
end;
end;
end;
ich beschäftige mich zur Zeit mit dem VirtualStringTree von M.Lischke.
Im Internet habe ich ein Beispiel gefunden, das ein ClientDataSet
als Verbindung zu einer Datenbank benutzt.
Ich versuche nun mit ADOConnection und BetterADODataSet eine
Verbindung zu einer Access Datenbank herzustellen.
Das Problem liegt in der Methode FindKey, die von ADO nicht
unterstützt wird. Mit SEEK habe ich es bereits versucht, bekomme aber nur leere Datensätze. IndexName habe ich gesetzt, CommandType=cmdTableDirect, CursorLocation=clUseServer und
CursorType=ctKeySet.
So funktionierts mit dem ClientDataSet (cds)
------------------------------------------------------
type
TBasicNode =
class
protected
FCaption : shortstring;
FID : longint;
FImageIndex : longint;
FHasChanged : boolean;
public
constructor Create( const sCaption : shortstring; const iID, iIndex: longint);
property Caption : shortstring read FCaption write FCaption;
property ID : longint read FID write FID;
property ImageIndex : longint read FImageIndex write FImageIndex;
property HasChanged : boolean read FHasChanged write FHasChanged;
end;
TBasicNodeAdd =
class(TBasicNode)
protected
FJobTitle : shortstring;
FAdd1 : shortstring;
FAdd2 : shortstring;
FAdd3 : shortstring;
public
property Add1 : shortstring read FAdd1 write FAdd1;
property Add2 : shortstring read FAdd2 write FAdd2;
property Add3 : shortstring read FAdd3 write FAdd3;
property JobTitle : shortstring read FJobTitle write FJobTitle;
end;
PTreeData = ^TTreeData;
TTreeData = record
FObject : TBasicNode;
end;
---------------------------------------------------
constructor TBasicNode.Create( const sCaption : shortstring; const iID, iIndex: longint);
begin
inherited Create;
FCaption := sCaption;
FID := iID;
FImageIndex := iIndex;
end;
const
FLDN_CustNo = 0;
FLDN_Company = 1;
FLDN_Addr1 = 2;
FLDN_Addr2 = 3;
FLDN_City = 4;
FLDN_State = 5;
FLDN_Zip = 6;
FLDN_Country = 7;
FLDN_Phone = 8;
FLDN_FAX = 9;
FLDN_TaxRate = 10;
FLDN_Contact = 11;
FLDN_LastInvoiceDate = 12;
---------------------------------------------------
procedure TfrmVTDBExample.VTGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var Text: WideString);
var
Data : PTreeData;
FObject : TBasicNodeAdd;
iLevel : integer;
begin
Text := '';
Data := Sender.GetNodeData(Node);
if Assigned(Data) and (Data.FObject <> nil) then with Data.FObject do
begin
iLevel := Sender.GetNodeLevel( Node );
case Column of
0:
begin
case TextType of
ttNormal:
begin
if iLevel = 0 then
begin
Text:=Caption
end
else
begin
if cds.FindKey([ID]) then with cds do
Text := Trim( Fields[ FLDN_Addr1 ].AsString + ' ' +
Fields[ FLDN_Addr2 ].AsString + ' ' +
Fields[ FLDN_City ].AsString + ' ' +
Fields[ FLDN_State ].AsString + ' ' +
Fields[ FLDN_Zip ].AsString + ' ' +
Fields[ FLDN_Country ].AsString );
end;
end;
ttStatic:
begin
Text := '';
end;
end;
end;
1:
begin
FObject := TBasicNodeAdd( Data.FObject );
case TextType of
ttNormal:
begin
if (iLevel = 0)and cds.FindKey([ID])
then with cds do
Text := Fields[ FLDN_Contact ].AsString;
end;
end;
end;
2:
begin
if TextType = ttNormal then
Text := ' ';
end;
end;
end;
end;
Comment