⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 《Delphi7编程100例》代码,书配资料
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DBTables, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure QueryGrid(DBName, Statement: String; Target: TStringGrid; Titles: Boolean);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.QueryGrid(DBName, Statement: String; Target: TStringGrid; Titles: Boolean);
var
  Col,Lin,i:Integer;
begin
  if Titles=True then i:=1
  else i:=0;
  With TQuery.Create(Nil) Do
  Try
    DatabaseName := DBName;
    SQL.Text := Statement;
    Open;
    If Not IsEmpty Then
    Begin
      Target.ColCount := FieldCount; 
      Target.RowCount := RecordCount+ i;
      Target.FixedCols := 0;
      Target.FixedRows := i;
      If Titles Then 
        For Col := 0 To FieldCount-1 Do 
          Target.Cells[Col,0] := Fields[Col].FieldName; 
      Lin := 0;
      While Not Eof Do 
      Begin 
        For Col := 0 To FieldCount-1 Do 
          Target.Cells[Col,Lin+Target.FixedRows] := 
                 Fields[Col].AsString;
        Next; 
        Inc(Lin); 
      End; 
    End; 
  Finally
    Close; 
    Free;
  End; 
end; { QueryGrid }
procedure TForm1.Button1Click(Sender: TObject);
begin
  QueryGrid(Edit1.Text,Memo1.Text,StringGrid1,True);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -