Forum > LCL

SOLVED INI read TColor

(1/3) > >>

Pe3s:
Hello forum members, how can I read and assign TColor saved in ini


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---[Skin]Start=$00FAAA2E End=$0098251F

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  INI: TIniFile;begin  if not OpenDialog1.Execute then Exit;  INI := TIniFile.Create(OpenDialog1.FileName);  try    with BCPanel1.Background.Gradient1 do    begin      StartColor := INI.ReadString('Skin', 'Start');      //EndColor := INI.Read;    end;  finally    INI.Free;  end;end;      

Lulu:
Hi, if StartColor and EndColor are TColor type, in line 9 and 10 write:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---StartColor := TColor(Ini.ReadString('Skin', 'Start').ToInteger);EndColor := TColor(Ini.ReadString('Skin', 'End').ToInteger);
But before, you should check the presence of filed Skin, Start and End in your INI file.

KodeZwerg:
Do not use "With" statements, it may be a trap for your own coding.

jamie:
I use WITH statements a lot and love them.

 As to the TINIFILE class, it has a READInteger already, there is no need to read the string and convert it.

MyIni.ReadInteger('Section', 'Name', Default_Value_Incase_It_Does_Not_Exist_Yet):Integer;

IT has lots of other types too.

CM630:
I am not sure if the TINIFile class is good for anything but legacy handling of past century apps.
Wiki says: "Currently only INI files compliant with the more restrictive Windows ini-file format are supported", I guess it also means "no unicode"?

Navigation

[0] Message Index

[#] Next page

Go to full version