VirtualTable Example
program VirtualTable;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
CNClrLib.ADONet.Client,
Data.DB;
var
table: TClrMemTable;
begin
try
// Here we create a DataTable with four columns.
table := TClrMemTable.Create(nil);
try
with table.FieldDefs.AddFieldDef do
begin
Name := 'Dosage';
DataType := ftInteger;
end;
with table.FieldDefs.AddFieldDef do
begin
Name := 'Drug';
DataType := ftString;
end;
with table.FieldDefs.AddFieldDef do
begin
Name := 'Patient';
DataType := ftString
end;
with table.FieldDefs.AddFieldDef do
begin
Name := 'Date';
DataType := ftDateTime
end;
// Here we open the dataset
table.Open;
// Here we add five Records.
table.InsertRecord([25, 'Indocin', 'David', Now]);
table.InsertRecord([50, 'Enebrel', 'Sam', Now]);
table.InsertRecord([10, 'Hydralazine', 'Christoff', Now]);
table.InsertRecord([21, 'Combivent', 'Janet', Now]);
table.InsertRecord([100, 'Dilantin', 'Melanie', Now]);
//Display Records
table.First;
while not table.Eof do
begin
Writeln(Format(chr(9) + '%s' + chr(9) + '%s' + chr(9) + '%s' + chr(9) + '%s',
[table.FieldByName('Dosage').AsString, table.FieldByName('Drug').AsString,
table.FieldByName('Patient').AsString, table.FieldByName('Date').AsString]));
table.Next;
end;
finally
table.Free;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end.