kbmmemtable使用filter的时候定位是不是有问题?我使用ADO和CDS执行同样的代码没有问题 ( 积分: 200 )

  • 主题发起人 主题发起人 hsgrass
  • 开始时间 开始时间
H

hsgrass

Unregistered / Unconfirmed
GUEST, unregistred user!
// 检查一下,好像是setrecno的时候有问题,,有没有人遇到或解决过<谢谢
procedure datasetToMenu(ds: tdataset;
ami: tmenuitem);
var
fl: string;
i: integer;
mi: tmenuitem;
begin
with dsdo
begin
if IsEmpty then
exit;
fl := filter;
filter := format('parentID = %d', [fieldbyname('id').AsInteger]);
//
find child
for i := 1 to recordcountdo
begin
ds.RecNo := i;
//form1.mmo2.Lines.Add(inttostr(i));
mi := tmenuitem.Create(ami);
mi.Caption := fieldbyname('caption').Value;
ami.Add(mi);
datasettomenu(ds, mi);
end;
filter := fl;
end;
end;

procedure adoDataSetToMenu(ds: TCustomADODataSet;
mi: tmenuitem);
begin
mi.Clear;
ds.DisableControls;
ds.Filter := '';
ds.Filtered := true;
// ds.IndexName := 'parentID';
datasettomenu(ds, mi);
ds.Filter := '';
ds.Filtered := false;
ds.EnableControls;
end;

procedure cdsDataSetToMenu(ds: tclientdataset;
mi: tmenuitem);
begin
mi.Clear;
ds.ReadOnly := true;
ds.DisableControls;
try
ds.Filter := '';
ds.Filtered := true;
ds.IndexFieldNames := 'parentID';
datasettomenu(ds, mi);
finally
ds.Filter := '';
ds.Filtered := false;
ds.ReadOnly := false;
ds.EnableControls;
end;
end;

procedure kbmMemDataSetToMenu(ds: TkbmCustomMemTable;
mi: tmenuitem);
begin
mi.Clear;
ds.ReadOnly := true;
ds.DisableControls;
try
ds.Filter := '';
ds.Filtered := true;
ds.IndexFieldNames := 'parentID';
datasettomenu(ds, mi);
finally
ds.Filter := '';
ds.Filtered := false;
ds.ReadOnly := false;
ds.EnableControls;
end;
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
cdsDataSetToMenu(cds1, mm1.Items);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
kbmmemtable1.LoadFromDataSet(qry1, [mtcpoStructure]);
end;

procedure TForm1.btn2Click(Sender: TObject);
var
i: integer;
begin
kbmMemDataSetToMenu(kbmmemtable1, mm1.Items);
//<----这个生成的结果不正确
end;
//--------------------------------------------------------------------------------------------------------
object kbmMemTable1: TkbmMemTable
DesignActivation = True
AttachedAutoRefresh = True
AttachMaxCount = 1
FieldDefs = <
item
Name = 'id'
Attributes = [faFixed]
DataType = ftInteger
end
item
Name = 'parentID'
Attributes = [faFixed]
DataType = ftInteger
end
item
Name = 'Caption'
DataType = ftWideString
Size = 20
end
item
Name = 'AutoRun'
Attributes = [faFixed]
DataType = ftBoolean
end
item
Name = 'FileName'
DataType = ftWideString
Size = 255
end>
IndexDefs = <>
SortOptions = []
PersistentBackup = False
ProgressFlags = [mtpcLoad, mtpcSave, mtpcCopy]
LoadedCompletely = True
SavedCompletely = True
FilterOptions = []
Version = '5.51'
LanguageID = 0
SortID = 0
SubLanguageID = 1
LocaleID = 1024
Left = 272
Top = 280
object kbmMemTable1id: TIntegerField
FieldName = 'id'
end
object kbmMemTable1parentID: TIntegerField
FieldName = 'parentID'
end
object kbmMemTable1Caption: TWideStringField
FieldName = 'Caption'
end
object kbmMemTable1AutoRun: TBooleanField
FieldName = 'AutoRun'
end
object kbmMemTable1FileName: TWideStringField
FieldName = 'FileName'
Size = 255
end
end
 
kbmmemtable 5.51在使用FILTER后如果使用recno定位不到, 但使用NEXT可以.
ADO和CDS没有这个问题......
怎样解决??
 
后退
顶部