📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, DBGrids, StdCtrls, DB, DBTables,gsEntityDataSet,gsEntityField, ComCtrls, TypInfo,
ExtCtrls, ADODB;
type
TCountry = class(TgsDataSetProxy)
published
property Name: TStringF index 0 read GetStringF;
property Capital: TStringF index 1 read GetStringF;
property Continent: TStringF index 2 read GetStringF;
property Area: TNumberF index 3 read GetNumberF;
property Population: TNumberF index 4 read GetNumberF;
//property ContinentName: TContinent. index 2 read GetStringF;
//属性方法
end;
TContinent = class(TgsDataSetProxy)
published
property ID: TIntF index 0 read GetIntF;
property Caption: TStringF index 1 read GetStringF;
end;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Panel1: TPanel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
ListView1: TListView;
Splitter1: TSplitter;
ADOConnection1: TADOConnection;
ADODataSet1: TADODataSet;
Button5: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses clRTTI;
{$R *.dfm}
{ TCountry }
procedure TForm1.Button1Click(Sender: TObject);
var
Country: TCountry;
KeyValue: string;
begin
Country := TCountry.Create(ADODataSet1);
try
ListView1.Items.Clear;
KeyValue := Country.Name.AsStr;
Country.First;
while (Country.ForEach) do
with ListView1.Items.Add do
begin
Caption := Country.Name.AsStr;
SubItems.Add(Country.Continent.AsStr);
SubItems.Add(Country.Capital.AsStr);
SubItems.Add(Country.Area.ToStr);
SubItems.Add(Country.Population.ToStr);
end;
Country.Locate(KeyValue);
finally
Country.Free;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Country: TCountry;
begin
Country := TCountry.Create(ADODataSet1);
with Country do
try
//Country.OnlySetEntityValue := True;
Country.BeginEdit;
Country.Name.AsStr := 'China';
Country.Capital.AsStr := 'beijing';
Country.Continent.AsStr := 'ASia';
//ShowMessage(Country.KeyName);
//ShowMessage(Country.Name.Value);
Country.Area.AsNum := 9600000;
Country.Population.AsNum := 1200000000;
//Country.Insert([Name,Capital,Continent,Area,Population],true);
//Country.Insert;
Country.Insert([Name,Capital,Continent],true);
//Country.EndEdit;
finally
//Country.OnlySetEntityValue := False;
Country.Free;
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
Country: TCountry;
begin
Country := TCountry.Create(ADODataSet1);
with Country do
try
//Country.OnlySetEntityValue := True;
Country.BeginEdit;
Country.Name.AsStr := 'China';
Country.Capital.AsStr := 'beijing';
Country.Continent.AsStr := 'ASia';
//ShowMessage(Country.KeyName);
//ShowMessage(Country.Name.Value);
Country.Area.AsNum := 9600000;
Country.Population.AsNum := 1200000000;
//Country.Insert([Name,Capital,Continent,Area,Population],true);
//Country.Insert;
Country.Update([Area,Population],Country.Name,True);
//Country.EndEdit;
finally
//Country.OnlySetEntityValue := False;
Country.Free;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
Country: TCountry;
begin
Country := TCountry.Create(ADODataSet1);
with Country do
try
BeginEdit;
Country.Name.AsStr := 'China';
Country.Delete(Country.Name);
//Country.EndEdit;
finally
//Country.OnlySetEntityValue := False;
Country.Free;
end;
end;
procedure TForm1.Button5Click(Sender: TObject);
var
Country: TCountry;
begin
Country := TCountry.Create(ADODataSet1);
with Country do
try
BeginEdit;
Country.Name.AsStr := '小日本';
Country.Delete(Country.Name);
finally
Country.Free;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -