Set DBGrid Option dgMultiSelect to true and put next code to the button handler: procedure TForm1.Button1Click(Sender: TObject); var X: Word; TempBook: TBookMark; begin with DBGrid1.DataSource.DataSet do begin DisableControls; with DBGrid1.SelectedRows do if Count<>0 then begin TempBook:=GetBook; for X:=0 to Count-1 do begin if IndexOf(Items[X])>-1 then begin Book:=Items[X]; ShowMessage(Fields[1].AsString); end; end; end; GotoBook(TempBook); FreeBook(TempBook); EnableControls; end; end;
呜,呜,呜,呜,那这个哩?procedure TForm1.Button1Click(Sender: TObject); var i, j: Integer; s: string; begin if DBGrid1.SelectedRows.Count>0 then with DBGrid1.DataSource.DataSet do for i:=0 to DBGrid1.SelectedRows.Count-1 do begin GotoBook(pointer(DBGrid1.SelectedRows.Items[i])); for j := 0 to FieldCount-1 do begin if (j>0) then s:=s+', '; s:=s+Fields[j].AsString; end; Listbox1.Items.Add(s); s:= ''; end; end;
//»ñÈ¡DBGridEh1ÖеÄÑ¡ÖÐÊý¾ÝÐÐ with DBGridEh1.DataSource.DataSet do for i:=0 to DBGridEh1.SelectedRows.Count-1 do begin GotoBook(pointer(DBGridEh1.SelectedRows.Items[i])); for j := 0 to FieldCount-1 do begin if (j>0) then s:=s+'-- '; s:=s+Fields[j].AsString; end; //ÅжϼǼÖظ´ if listbox1.Items.IndexOf(s)<0 then begin Listbox1.Items.Add(s); s:=''; end else begin MessageDlg('ÄúÒÑÌí¼ÓÁË"'+trim(s)+'" ÕâÌõ¼Ç¼!',mtInformation,[mbok],0); s:= ''; end; end; 一定行
procedure TForm1.Button1Click(Sender: TObject);
var
X: Word;
TempBook: TBookMark;
begin
with DBGrid1.DataSource.DataSet do
begin
DisableControls;
with DBGrid1.SelectedRows do
if Count<>0 then
begin
TempBook:=GetBook;
for X:=0 to Count-1 do
begin
if IndexOf(Items[X])>-1 then
begin
Book:=Items[X];
ShowMessage(Fields[1].AsString);
end;
end;
end;
GotoBook(TempBook);
FreeBook(TempBook);
EnableControls;
end;
end;
var
i, j: Integer;
s: string;
begin
if DBGrid1.SelectedRows.Count>0 then
with DBGrid1.DataSource.DataSet do
for i:=0 to DBGrid1.SelectedRows.Count-1 do
begin
GotoBook(pointer(DBGrid1.SelectedRows.Items[i]));
for j := 0 to FieldCount-1 do
begin if (j>0) then s:=s+', ';
s:=s+Fields[j].AsString;
end;
Listbox1.Items.Add(s);
s:= '';
end;
end;
with DBGridEh1.DataSource.DataSet do
for i:=0 to DBGridEh1.SelectedRows.Count-1 do begin
GotoBook(pointer(DBGridEh1.SelectedRows.Items[i]));
for j := 0 to FieldCount-1 do begin
if (j>0) then s:=s+'-- ';
s:=s+Fields[j].AsString;
end;
//ÅжϼǼÖظ´
if listbox1.Items.IndexOf(s)<0 then
begin
Listbox1.Items.Add(s);
s:='';
end
else
begin
MessageDlg('ÄúÒÑÌí¼ÓÁË"'+trim(s)+'" ÕâÌõ¼Ç¼!',mtInformation,[mbok],0);
s:= '';
end;
end;
一定行