Delphi 将备忘录中的stringlist项从表POS_CatBreakDownValue检索到tchecklistbox中
我对如何从表中检索memo中的项目到tchecklistbox有问题…在此之前,我执行了将已签入memo中的项目插入tbl POS_CatBreakDownValue的过程..但现在我想知道如何从表中检索项目并自动签入tchecklistbox…谢谢..这里是我插入清单的过程我希望任何人都能帮助我谢谢Delphi 将备忘录中的stringlist项从表POS_CatBreakDownValue检索到tchecklistbox中,delphi,Delphi,我对如何从表中检索memo中的项目到tchecklistbox有问题…在此之前,我执行了将已签入memo中的项目插入tbl POS_CatBreakDownValue的过程..但现在我想知道如何从表中检索项目并自动签入tchecklistbox…谢谢..这里是我插入清单的过程我希望任何人都能帮助我谢谢 procedure TfrmSysConfig.saveCatBreakDownValue; var lstCat:TStringList;
procedure TfrmSysConfig.saveCatBreakDownValue;
var
lstCat:TStringList;
i :integer;
begin
lstcat := TStringList.Create;
try
for i:=0 to clCat.Items.Count-1 do begin
if clCat.Checked[i] then begin
lstcat.Add(clcat.Items.Strings[i]);
end;
end;
tblMainPOS_CatBreakDownValue.Value := lstCat.Text;
finally
lstcat.Free;
end;
end;
我不太清楚你的问题100% TCheckListBox可以使用Checked属性选中或取消选中项目
CheckListBox.Checked[Index] := True/False;
由于听起来像是比较字符串,因此可能需要根据字符串确定TCheckListBox中的索引,具体操作如下:
CheckListBox1.Items.IndexOf('StringToFind')
如果未找到字符串,则结果为-1
如果要检查TMemo控件中的行并查看它们是否作为行存在于表中,可以执行以下操作
While not Table.EOF do
begin
if Memo1.lines.IndexOf(Table.FieldByName('MyField').AsString) = -1 then
begin
// What you want to do if not found
end
else
begin
// what you want to do if it is found.
end;
Table.Next;
end;
读取代码我猜您在数据库中有一个memo字段,您正在从/向中读取和写入检查值。您还有一个预定义的可检查项列表
因此,您需要创建一个新的字符串列表,并将字段读回其中,以显示编写代码。对于列表中的每个项目,获取索引并进行检查
类似于
procedure TfrmSysConfig.saveCatBreakDownValue;
var
lstCat: TStringList;
i, Index:integer;
begin
lstcat := TStringList.Create;
try
lstcat.Text = tblMainPOS_CatBreakDownValue.Value;
for i:=0 to lstcat.Count-1 do
begin
Index := clCat.Items.IndexOf(lstcat.Items[i])
if Index > -1 then
begin
clCat.Checked[Index] := True;
end;
end;
finally
lstcat.Free;
end;
end;
procedure TfrmSysConfig.saveCatBreakDownValue;
var
lstCat: TStringList;
i, Index:integer;
begin
lstcat := TStringList.Create;
try
lstcat.Text = tblMainPOS_CatBreakDownValue.Value;
for i:=0 to lstcat.Count-1 do
begin
Index := clCat.Items.IndexOf(lstcat.Items[i])
if Index > -1 then
begin
clCat.Checked[Index] := True;
end;
end;
finally
lstcat.Free;
end;
end;