Board index » delphi » SpinEdit "Read and Write" To IniFile

SpinEdit "Read and Write" To IniFile


2003-07-14 06:32:34 AM
delphi106
Hello All;
I am using the following to read and write to an IniFile taking the Values
From the "SpinEdit" control.
In the "ReadInteger; "
It has values already assigned to it. And I need to allow for User Input.
How would I do this. When I try to write it to except a String Value, I
Get an error>
[Error] WeatherAbout.pas(89): Incompatible types: 'Integer' and 'String'
On a line like this
TimerHourEdit.Value := ReadInteger( 'Weather_Refresh', 'Hour', '' );
Any idea's would be greatfully appreciated
Wayne
========Code Provided Below======
procedure TFireHelp.FormCreate(Sender: TObject);
begin
ReadConfiguration
end;
procedure TFireHelp.FormClose(Sender: TObject; var Action: TCloseAction);
var
GlobalTimeIni: TIniFile;
begin
GlobalTimeIni := TIniFile.Create(ExtractFilePath(ParamStr(0)) +
'Time.ini');
TRY
with GlobalTimeIni do
begin
WriteInteger( 'Weather_Refresh', 'Hour', TimerHourEdit.Value );
WriteInteger( 'Weather_Refresh', 'Minute', TimerMinutesEdit.Value );
WriteInteger( 'Weather_Refresh', 'Second', TimerSecondsEdit.Value );
end;
FINALLY
GlobalTimeIni.Free;
END;
end;
Procedure TFireHelp.ReadConfiguration;
var
GlobalTimeIni: TIniFile;
begin
GlobalTimeIni := TIniFile.Create(ExtractFilePath(ParamStr(0)) +
'Time.ini');
TRY
with GlobalTimeIni do
begin
TimerHourEdit.Value := ReadInteger( 'Weather_Refresh', 'Hour', 25 );
TimerMinutesEdit.Value := ReadInteger( 'Weather_Refresh', 'Minutes',
25 );
TimerSecondsEdit.Value := ReadInteger( 'Weather_Refresh', 'Seconds',
25 );
end;
FINALLY
GlobalTimeIni.Free;
END; end;
 
 

Re:SpinEdit "Read and Write" To IniFile

Hi Wayne & Carr,
Quote
When I try to write it to except a String Value, I
Get an error>
[Error] WeatherAbout.pas(89): Incompatible types: 'Integer' and 'String'
On a line like this
TimerHourEdit.Value := ReadInteger( 'Weather_Refresh', 'Hour', '' );
If you use ReadInteger( ) then you have to pass a integer value as default !
to avoid exceptions, you could do sth like this:
TimerHourEdit.Value := StrtoInt64Def(ReadString( 'Weather_Refresh', 'Hour',
0), -1);
Quote
Any idea's would be greatfully appreciated

Wayne
HTH,
Michael
 

Re:SpinEdit "Read and Write" To IniFile

"Fauschti"
Quote

If you use ReadInteger( ) then you have to pass a integer value as default
!
to avoid exceptions, you could do sth like this:

TimerHourEdit.Value := StrtoInt64Def(ReadString( 'Weather_Refresh',
'Hour',
0), -1);

>Any idea's would be greatfully appreciated
>
>Wayne

HTH,
Michael
Hello Michael;
Thank you for your Response. But unfortunately. This gives the same error
message
[Error] WeatherAbout.pas(89): Incompatible types: 'String' and 'Integer'
And it drops the cursor here : , -1);
Any idea's?
Wayne
 

Re:SpinEdit "Read and Write" To IniFile

Hi Wayne & Carr,
this works, i compiled it ;-)
procedure TForm1.Button1Click(Sender: TObject);
var
ini : TIniFile;
I : Integer;
begin
ini := TIniFile.Create('');
I := StrtoInt64Def(ini.ReadString('Weather_Refresh', 'Hour', '0'), -1);
ini.Free;
end;
i you looked at the code i posted before, you figure out, that readstring( )
would require a string as default value, and i passed an integer, because i
first corrected your first post and than changed it to readstring *g*
regards,
Michael
Quote
Hello Michael;
Thank you for your Response. But unfortunately. This gives the same
error
message

[Error] WeatherAbout.pas(89): Incompatible types: 'String' and 'Integer'
And it drops the cursor here : , -1);

Any idea's?

Wayne
 

Re:SpinEdit "Read and Write" To IniFile

Hi Wayne & Carr,
Your code looks fine to me. maybe the values simply do not exist in the ini
file - or the ini file does not exist? you could also play with the default
values, to see, if sth. changes.
e.g.: TimerHourEdit.Value := StrtoInt64Def(ReadString('Weather_Refresh',
'Hour', '5'), 10);
please note, that the string default ( in this case '5' ) will be used, if
the value cannot be found in the ini, the other default value ( in this case
10 ) will be used, if the string we get from the ini is not a valid Int64
value.
HTH,
Michael
Quote
Procedure TFireHelp.ReadConfiguration;
var
GlobalTimeIni: TIniFile;
begin
GlobalTimeIni := TIniFile.Create(ExtractFilePath(ParamStr(0)) +
'Time.ini');
TRY
with GlobalTimeIni do
begin
TimerHourEdit.Value := StrtoInt64Def(ReadString('Weather_Refresh', 'Hour',
'0'), -1);
TimerMinutesEdit.Value := StrtoInt64Def(ReadString('Weather_Refresh',
'Minutes', '0'), -1);
TimerSecondsEdit.Value := StrtoInt64Def(ReadString('Weather_Refresh',
'Seconds', '0'), -1);
end;
FINALLY
GlobalTimeIni.Free;
END; end;

So at least we got the compiling done, but what is going on with reading
???

Wayne
 

Re:SpinEdit "Read and Write" To IniFile

got it working.
was "1" letter off in the name of the line in the IniFile
Weather_Refresh was Wether_Refresh
And then the " Readconfiguration"
Was not in the "OnCreate"
So it is working now :-)
Please forgive me for the agrivation .
Trying to do to many things at once I reacon.
But it is working.
Wayne
p.s.
This is for a project that I along with another developer are working on,
That is fixing to be released as an Open Project for others to work on.
Could you please give me your whole name so that I can add it to the project
For the Help in the "IniFile w/TSpinEdit" ?
will post the URL to the site that the project will be on, once the site is
up and ready to go.
It will be posted to the 3rdparty groups. under:
ANN: The Weather Project
Thank you
Wayne