converting delphi code to c#

B

BillB

Hi,
I've got some Delphi code that I need to convert c#, the code is used in a
timer to delete an entry from a TListView in Delphi.
The Delphi code is below:

procedure TfrmALSECServer.tmrALSECTimer(Sender : TObject);
var
i : Integer;
Item : TListItem;
obj : TMyObj;
begin
try
for i := vListView.Items.Count - 1 downto 0 do
begin
Item := vListView.items;
obj := TMyObj(Item.data);
if (now - obj.rqTime) > {(1.0 / (24 * 60 * 3)) then//}(1.0 / 24) then
begin
//dispose of record after 1 hour
obj.Free;
vListView.items.Delete(i);
end
end;
//switch off timer if list empty.
if (vListView.Items.Count = 0) then
tmrTimer.Enabled := False;
Except
on e : exception do
begin
ShowMessage('tmrTimer: '+e.message);
end;
End;
end;

The Object and Record used are below:

TMyObj = class(TObject)
id : Integer;
rqTime: TDateTime;
info : TMyDetails;
end;

TMyDetails = record
cValidInfo : Boolean;
Line1 : Widestring;
Line2 : Widestring;
Line3 : Widestring;
....
....
....
Line22 : Widestring;
Line23 : Widestring;
Line24 : Widestring;
end;

If anyone knows how to convert this or of a program which will do it that
would be great.

Thanks
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

It's fairly trivial to do so, you can almost duplicate each line in C#, what
is the problem you have?
 
B

BillB

problem I am having is trying to figure out how I can get the rqTime from
the ListView, it is in a column called Rq, and then need to delete this row
if it is over an hour old.
I'm new to C#, been doing Delphi for last 10 years, but this app is to be
re-written in C#


thanks



Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

It's fairly trivial to do so, you can almost duplicate each line in C#,
what is the problem you have?

BillB said:
Hi,
I've got some Delphi code that I need to convert c#, the code is used in
a timer to delete an entry from a TListView in Delphi.
The Delphi code is below:

procedure TfrmALSECServer.tmrALSECTimer(Sender : TObject);
var
i : Integer;
Item : TListItem;
obj : TMyObj;
begin
try
for i := vListView.Items.Count - 1 downto 0 do
begin
Item := vListView.items;
obj := TMyObj(Item.data);
if (now - obj.rqTime) > {(1.0 / (24 * 60 * 3)) then//}(1.0 / 24)
then
begin
//dispose of record after 1 hour
obj.Free;
vListView.items.Delete(i);
end
end;
//switch off timer if list empty.
if (vListView.Items.Count = 0) then
tmrTimer.Enabled := False;
Except
on e : exception do
begin
ShowMessage('tmrTimer: '+e.message);
end;
End;
end;

The Object and Record used are below:

TMyObj = class(TObject)
id : Integer;
rqTime: TDateTime;
info : TMyDetails;
end;

TMyDetails = record
cValidInfo : Boolean;
Line1 : Widestring;
Line2 : Widestring;
Line3 : Widestring;
....
....
....
Line22 : Widestring;
Line23 : Widestring;
Line24 : Widestring;
end;

If anyone knows how to convert this or of a program which will do it that
would be great.

Thanks

 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You can get the subitems using ListView.Items[ rowNumber].SubItems [
ColumnNumber] and convert it to a DateTime

BillB said:
problem I am having is trying to figure out how I can get the rqTime from
the ListView, it is in a column called Rq, and then need to delete this
row if it is over an hour old.
I'm new to C#, been doing Delphi for last 10 years, but this app is to be
re-written in C#


thanks



Ignacio Machin ( .NET/ C# MVP ) said:
Hi,

It's fairly trivial to do so, you can almost duplicate each line in C#,
what is the problem you have?

BillB said:
Hi,
I've got some Delphi code that I need to convert c#, the code is used in
a timer to delete an entry from a TListView in Delphi.
The Delphi code is below:

procedure TfrmALSECServer.tmrALSECTimer(Sender : TObject);
var
i : Integer;
Item : TListItem;
obj : TMyObj;
begin
try
for i := vListView.Items.Count - 1 downto 0 do
begin
Item := vListView.items;
obj := TMyObj(Item.data);
if (now - obj.rqTime) > {(1.0 / (24 * 60 * 3)) then//}(1.0 / 24)
then
begin
//dispose of record after 1 hour
obj.Free;
vListView.items.Delete(i);
end
end;
//switch off timer if list empty.
if (vListView.Items.Count = 0) then
tmrTimer.Enabled := False;
Except
on e : exception do
begin
ShowMessage('tmrTimer: '+e.message);
end;
End;
end;

The Object and Record used are below:

TMyObj = class(TObject)
id : Integer;
rqTime: TDateTime;
info : TMyDetails;
end;

TMyDetails = record
cValidInfo : Boolean;
Line1 : Widestring;
Line2 : Widestring;
Line3 : Widestring;
....
....
....
Line22 : Widestring;
Line23 : Widestring;
Line24 : Widestring;
end;

If anyone knows how to convert this or of a program which will do it
that would be great.

Thanks

 
Top