程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 拷貝DBGrid當前行

拷貝DBGrid當前行

編輯:Delphi
procedure CopyCurrentDBLine(DBGrid: TDBGrid);
  var
    i: Integer;
    Line: String;
  begin
    for i := 0 to DBGrid.Columns.Count - 1 do begin
      if Assigned(DBGrid.Columns.Grid.FIElds[i]) then
        if Line = '' then
          Line := DBGrid.Columns.Grid.FIElds[i].Text
        else
          Line := Line + ' ' + DBGrid.Columns.Grid.FIElds[i].Text;
    end;
    Clipboard.SetTextBuf(pchar(Line));
  end;
  //感謝深思提供技術支持:)
  
  procedure CopyDBData(DBGrid: TDBGrid);
  const
    CRLF = #13#10;
  var
    i: Integer;
    Lines: String;
    BookMark: Pointer;
  begin
    BookMark := DBGrid.DataSource.DataSet.GetBookmark;
    DBGrid.DataSource.DataSet.First;
   
    while not DBGrid.DataSource.DataSet.Eof do begin
      for i := 0 to DBGrid.Columns.Count - 1 do begin
        if Assigned(DBGrid.Columns.Grid.FIElds[i]) then
          if Lines = '' then
            Lines := DBGrid.Columns.Grid.FIElds[i].Text
          else
            if i = 0 then
              Lines := Lines + DBGrid.Columns.Grid.FIElds[i].Text
            else
              Lines := Lines + ' ' + DBGrid.Columns.Grid.FIElds[i].Text;
      end;
      Lines := Lines + CRLF;
      DBGrid.DataSource.DataSet.Next;
    end;
    ClipBoard.SetTextBuf(PChar(Lines));
    DBGrid.DataSource.DataSet.GotoBookmark(BookMark);
  end;
  
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved