🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.delphi.database.dotnet
2 messages
2 total messages Started by Eric Orilla Wed, 04 Oct 2006 08:21
DataTable.NewRow
#131
Author: Eric Orilla
Date: Wed, 04 Oct 2006 08:21
52 lines
2093 bytes
in C# the following compiles successfully

column = new DataColumn();
column.DataType = System.Type.GetType("System.Int32");
column.ColumnName = "id";
Columns.Add(column);
keys[0] = column;

column = new DataColumn();
column.DataType = System.Type.GetType("System.Double");
column.ColumnName = "ic";
Columns.Add(column);

// Create second column.
column = new DataColumn();
column.DataType = Type.GetType("System.String");
column.ColumnName = "item";
Columns.Add(column);

PrimaryKey = keys;

DataRow row;
row["id"] = 1;
row["ic"] = 123.456;
row["item"] = "Item1";
Rows.Add(row);

in Delphi equivalent produces compilation error

column := DataColumn.Create;
column.DataType := System.Type.GetType('System.Int32');
column.ColumnName := 'id';
Columns.Add(column);

column := DataColumn.Create;
column.DataType := System.Type.GetType('System.Double');
column.ColumnName := 'ic';
Columns.Add(column);

column := DataColumn.Create;
column.DataType := System.Type.GetType('System.String');
column.ColumnName := 'item';
Columns.Add(column);

row := NewRow();
row['id'] := 1; <**** Incompatible types: 'Object' and 'Integer'
row['ic'] := 123.456; <**** Incompatible types: 'Object' and 'Double'
row['item'] := 'Item1';
Rows.Add(row);

What is the rigth way of doing this...
Re: DataTable.NewRow
#132
Author: Wayne Niddery [TeamB]
Date: Wed, 04 Oct 2006 14:01
22 lines
1781 bytes
Eric Orilla wrote:
> row['id'] := 1; <**** Incompatible types: 'Object' and 'Integer'
> row['ic'] := 123.456; <**** Incompatible types: 'Object' and 'Double'

> What is the rigth way of doing this...


Just cast them (called boxing in this case because it's wrapping value types 
into objects):

row['id'] := TObject(1);
row['ic'] := TObject(123.456);

Alternatively, add {$AUTOBOX ON} to the unit and the compiler will do the 
boxing for you.

-- 
Wayne Niddery - Winwright, Inc (www.winwright.ca)
"If there is any principle of the Constitution that more imperatively
calls for attachment than any other, it is the principle of free
thought � not free thought for those who agree with us, but freedom for
the thought that we hate." - Oliver Wendell Holmes 
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads