|
Insert
the rows into the dataset that is connected to the grid.
This
is only D2005 compatible...
======= unit ==============
unit
Unit55;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, Grids, DBGrids, DBClient, StdCtrls; type
TForm55 = class(TForm) DataSource1: TDataSource; ClientDataSet1: TClientDataSet; DBGrid1: TDBGrid; Button1: TButton; Button2: TButton; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var
Form55: TForm55; implementation
{$R
*.dfm}
procedure TForm55.Button1Click(Sender: TObject);
var lList: TStringList; lStr: String; lCnt: Integer; begin lList := TStringList.Create; try lList.Add('Item0'); lList.Add('Item1'); lList.Add('Item2'); lList.Add('Item3'); lList.Add('Item4'); lList.Add('Item5'); ClientDataSet1.FieldDefs.Add('FieldOne', ftInteger, 0, False); ClientDataSet1.FieldDefs.Add('FieldTwo', ftString, 10, False); ClientDataSet1.CreateDataSet; ClientDataSet1.Active := True; lCnt := 0; for lStr in lList do begin ClientDataSet1.Append; ClientDataSet1.Fields[0].AsInteger := lCnt; ClientDataSet1.Fields[1].AsString := lStr; ClientDataSet1.Post; inc(lCnt); end; finally FreeAndNil(lList); end; end; procedure TForm55.Button2Click(Sender: TObject);
begin ClientDataSet1.Active := False; close; end; end.
======
form ==============
object
Form55: TForm55
Left = 0 Top = 0 Width = 391 Height = 270 Caption = 'Form55' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'Tahoma' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object DBGrid1: TDBGrid Left = 8 Top = 40 Width = 369 Height = 193 DataSource = DataSource1 TabOrder = 0 TitleFont.Charset = DEFAULT_CHARSET TitleFont.Color = clWindowText TitleFont.Height = -11 TitleFont.Name = 'Tahoma' TitleFont.Style = [] end object Button1: TButton Left = 8 Top = 8 Width = 75 Height = 25 Caption = 'Execute' TabOrder = 1 > end object Button2: TButton Left = 304 Top = 8 Width = 75 Height = 25 Caption = 'Close' TabOrder = 2 > end object DataSource1: TDataSource DataSet = ClientDataSet1 Left = 184 Top = 120 end object ClientDataSet1: TClientDataSet Aggregates = <> Params = <> Left = 192 Top = 128 end end cheers,
JED
|
_______________________________________________ Delphi mailing list [email protected] http://ns3.123.co.nz/mailman/listinfo/delphi
