home *** CD-ROM | disk | FTP | other *** search
/ Delphi Anthology / aDELPHI.iso / Runimage / Delphi50 / Demos / Midas / InternetExpress / InetXCenter / componentsinfoeditorunit1.pas < prev    next >
Pascal/Delphi Source File  |  1999-08-11  |  3KB  |  109 lines

  1. {  InternetExpress sample application.
  2.  
  3.    The InetXCenter sample application displays information
  4.    about various InternetExpress components.  This information
  5.    is stored in a local file created by TClientDataSet.
  6.  
  7.    This application is used to edit the information in the
  8.    local file.
  9.  
  10.    ClientDataSet1.FileName is the file used to store the CDS.
  11.    When ClientDataSet1 is activated at design time, you may
  12.    not see the data seen at runtime because the application
  13.    output directory may be different than the project directory.
  14.  
  15. }
  16.  
  17. unit ComponentsInfoEditorUnit1;
  18.  
  19. interface
  20.  
  21. uses
  22.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  23.   StdCtrls, DBCtrls, ExtCtrls, Grids, DBGrids, Db, DBClient;
  24.  
  25. type
  26.   TForm1 = class(TForm)
  27.     DataSource1: TDataSource;
  28.     DBNavigator1: TDBNavigator;
  29.     Panel1: TPanel;
  30.     Panel2: TPanel;
  31.     Panel3: TPanel;
  32.     Splitter1: TSplitter;
  33.     DBGrid1: TDBGrid;
  34.     DBComboBox1: TDBComboBox;
  35.     DBMemo1: TDBMemo;
  36.     DBMemo2: TDBMemo;
  37.     Button1: TButton;
  38.     Button2: TButton;
  39.     ClientDataSet1: TClientDataSet;
  40.     procedure Button1Click(Sender: TObject);
  41.     procedure Button2Click(Sender: TObject);
  42.     procedure ClientDataSet1AfterInsert(DataSet: TDataSet);
  43.   private
  44.     { Private declarations }
  45.   public
  46.     { Public declarations }
  47.   end;
  48.  
  49. var
  50.   Form1: TForm1;
  51.  
  52. implementation
  53.  
  54. {$R *.DFM}
  55.  
  56. procedure TForm1.Button1Click(Sender: TObject);
  57. begin
  58.   if ClientDataSet1.Modified then
  59.     ClientDataSet1.Post;
  60.   ClientDataSet1.SaveToFile(ClientDataSet1.FileName);
  61. end;
  62.  
  63. procedure TForm1.Button2Click(Sender: TObject);
  64. begin
  65.   ClientDataSet1.Close;
  66.   ClientDataSet1.LoadFromFile(ClientDataSet1.FileName);
  67. end;
  68.  
  69. procedure TForm1.ClientDataSet1AfterInsert(DataSet: TDataSet);
  70. begin
  71.   { Workaround bug in which memo text can't be created once
  72.     a record is inserted. }
  73.   DBMemo1.Text := ' ';
  74.   DBMemo2.Text := ' ';
  75. end;
  76.  
  77. { The structure of a client data set can't be changed
  78. without losing the data.  To change the structure, create
  79. a new clientdataset and use code like this to copy data
  80. from the old dataset to the new dataset.
  81. }
  82.  
  83. {
  84. procedure TForm1.Button5Click(Sender: TObject);
  85.  
  86.   procedure CopyValue(FieldName: string);
  87.   begin
  88.     ClientDataSet2.FieldByName(FieldName).Value :=
  89.       ClientDataSet1.FieldByName(FieldName).Value;
  90.   end;
  91. begin
  92.   ClientDataSet1.Active := true;
  93.   ClientDataSet2.Active := true;
  94.   while not ClientDataSet1.eof do
  95.   begin
  96.     ClientDataSet2.Insert;
  97.     CopyValue('ClassName');
  98.     CopyValue('Description');
  99.     CopyValue('ShortDescription');
  100.     CopyValue('Usage');
  101.     ClientDataSet2.Post;
  102.     ClientDataSet1.Next;
  103.   end;
  104. end;
  105. }
  106.  
  107.  
  108. end.
  109.