Delphi to C#

Delphi to C#

Page 1 of 1

6 Replies - 3078 Views - Last Post: 12 November 2010 - 07:45 AM Rate Topic: -----

#1 Guest_Chintan*


Reputation:

Delphi to C#

Posted 11 November 2010 - 01:50 PM

Can any one help me to convert this delphi code to C#.

class function TShrinkConfig.MyVersion: WORD;
var
  ini: TIniFile;
begin
  ini := TIniFile.Create(gsIniFile);
  Result := ini.ReadInteger(
      SHRINK_INI_SETUP_SECTION,
      SHRINK_INI_MYVERSION,
      SHRINK_INI_VERSION_1);

  ini.Free;
end;

if (not ini.ValueExists(SHRINK_INI_VERSIONS_SECTION, IntToStr(version))) then
....


I searched online that TiniFile corresponds to FileStream in C#.
But i am not able to understand and convert it into C#.

Help would be really appreciated.

MOD EDIT: When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 11 November 2010 - 01:55 PM


Is This A Good Question/Topic? 0

Replies To: Delphi to C#

#2 Ionut  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 385
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Delphi to C#

Posted 11 November 2010 - 02:15 PM

Quote

I searched online that TiniFile corresponds to FileStream in C#.

Actually, they not. FileStream in C# doesn't have the capability to manipulate ini files in the same way TIniFile class does. So, you have to build your own class that reads an ini file and does some actions. There is no simple, equivalent code for your issue.
Was This Post Helpful? 1
  • +
  • -

#3 Guest_Chintan*


Reputation:

Re: Delphi to C#

Posted 11 November 2010 - 02:57 PM

View PostIonut, on 11 November 2010 - 01:15 PM, said:

Quote

I searched online that TiniFile corresponds to FileStream in C#.

Actually, they not. FileStream in C# doesn't have the capability to manipulate ini files in the same way TIniFile class does. So, you have to build your own class that reads an ini file and does some actions. There is no simple, equivalent code for your issue.


Ok
So is there any method to read or write or search values from ini file ?
Was This Post Helpful? 0

#4 karabasf  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 202
  • View blog
  • Posts: 417
  • Joined: 29-August 10

Re: Delphi to C#

Posted 11 November 2010 - 03:03 PM

I think you can use a Streamreader for that.

Furthermore, I know there are some tutorials of reading and writing a file in the C# tutorials section, but I am not sure where.

For information about the streamreader, you can find that here:
http://msdn.microsof...reamreader.aspx

This post has been edited by karabasf: 11 November 2010 - 03:04 PM

Was This Post Helpful? 0
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Delphi to C#

Posted 11 November 2010 - 03:24 PM

Not C# managed code, but you can use P/Invoke and GetPrivateProfileString.
Was This Post Helpful? 0
  • +
  • -

#6 Rico Diesel  Icon User is offline

  • D.I.C Head

Reputation: 62
  • View blog
  • Posts: 122
  • Joined: 06-May 10

Re: Delphi to C#

Posted 12 November 2010 - 01:07 AM

Maybe this article will help. shown functions only support strings. Simply add type checking into the class before you write to the ini file (or after in case of reading).
Was This Post Helpful? 0
  • +
  • -

#7 Guest_Chintan*


Reputation:

Re: Delphi to C#

Posted 12 November 2010 - 07:45 AM

View PostRico Diesel, on 12 November 2010 - 12:07 AM, said:

Maybe this article will help. shown functions only support strings. Simply add type checking into the class before you write to the ini file (or after in case of reading).


Thanks.
This solved my problem.
Was This Post Helpful? 0

Page 1 of 1