.ini files

This forum is meant for questions and discussions about the X# language and tools
User avatar
Neale
Posts: 24
Joined: Sat Mar 25, 2017 10:40 pm
Location: United Kingdom

.ini files

Post by Neale »

Sorry late reply.
Much appreciate your help, the GetString() Method still is not returning a string from the .INI file ?
I do have a small working sample if required ? showing no return value.
User avatar
Chris
Posts: 4900
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

.ini files

Post by Chris »

Hi Neale,

Yes, please send the sample to have a look, including both the ini file and the code you are using!
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Neale
Posts: 24
Joined: Sat Mar 25, 2017 10:40 pm
Location: United Kingdom

.ini files

Post by Neale »

IniFileSpec_Test is a XVIDE project using StdSDI as a framework, step through Function SetUpIni() and you will see the vars in the debug window, and the App_Paths.INI will be changed and updated. An empty App_Paths.INI is in IniFileSpec_Test directory.
User avatar
Chris
Posts: 4900
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

.ini files

Post by Chris »

Hi Neale,

Ah right, I missed this method indeed. Thanks for the very good sample, here's an updated method code that you can use:

Code: Select all

METHOD GetString( cSection AS STRING, cEntry AS STRING, cDefault AS STRING ) AS STRING 
   LOCAL dwBytes AS DWORD
   LOCAL cString AS STRING

	IF SELF:_lFileExists
		LOCAL p := String2Psz(Space(250)) AS PSZ
		dwBytes := GetPrivateProfileString(String2Psz(cSection), String2Psz(cEntry), String2Psz(cDefault), p, 250, String2Psz(SELF:FullPath))
	   	cString := Left(Psz2String(p), dwBytes)
	ENDIF

RETURN cString
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
Neale
Posts: 24
Joined: Sat Mar 25, 2017 10:40 pm
Location: United Kingdom

.ini files

Post by Neale »

Thank you Chris, all good.
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

.ini files

Post by wriedmann »

Hi Chris,
would it not be better to use the .NET way of calling the functions?

Code: Select all

[DllImport("kernel32.dll",CharSet:=CharSet.Ansi,EntryPoint:="GetPrivateProfileString")];
static method GetString(lpAppName as string, lpKeyName as string, lpDefault as string, lpBuffer as StringBuilder, nSize as dword, lpFileName as string) as dword pascal

public virtual method GetString( cSection as string, cEntry as string, cDefault as string ) as string
	local cReturn 		as string
	local oReturn 		as System.Text.StringBuilder

	oReturn 			:= System.Text.StringBuilder{ _nStringLen }
	IniFile.GetString( cSection, cEntry, cDefault, oReturn, dword( _nStringLen ), _cFileName )
	cReturn				:= oReturn:ToString()

	return cReturn
I remember that I wrote that code with your help several years ago.

Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
User avatar
Chris
Posts: 4900
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

.ini files

Post by Chris »

Hi Wolfgang,

Yeah, absolutely! I just tried to adjust the code this time with the least possible amount of changes, but your way is definitely much more efficient!
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
Post Reply