Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > Apps

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 09-13-2010, 10:14 AM
Shaun Hand Shaun Hand is offline
Junior Member
 
Join Date: Aug 2010
Posts: 24
Question INI read PageControl1.Pages Visible

I'm using an ini file to store personal preferences, and depending on if this file exists it will either load the settings, and hide the setup page, or make the setup page visible and be the active tab.

This is what I'm using.

procedure TForm1.ReadINIExecute(Sender: TObject);
var
ini: TIniFile;
begin
// Create INI Object and open or create file test.ini
ini := TIniFile.Create(GetSpecialFolderPath($001a)+'\UTCT \UTCT.ini');
try
if not ini.ValueExists('Setup', 'Exist')
then begin PageControl1.Pages[4].TabVisible :=True; PageControl1.TabIndex :=4; btnSave.Enabled :=True;
end else PageControl1.TabIndex :=0; PageControl1.Pages[4].TabVisible :=False;
// Read String value from the INI file.
Edit7.Text := ini.ReadString ('Setup', 'Tel1', '' );
...


The problem is that if the ini does not exist, then it still defaults to TabIndex :=0, and the Tab is still not visible.

Any ideas?
Reply With Quote
  #2  
Old 09-13-2010, 11:58 AM
Glenn1234 Glenn1234 is offline
Senior Member
 
Join Date: Aug 2009
Posts: 131
Default

Quote:
Originally Posted by Shaun Hand View Post
The problem is that if the ini does not exist, then it still defaults to TabIndex :=0, and the Tab is still not visible.

Any ideas?
It looks like you're confusing TInifile with TRegistry or TRegIniFile by the looks of things. I'm surprised what you posted even compiles, since ValueExists() only is consistent with TRegistry (TRegIniFile being derived from it).

What you need to do is simply read the string and then parse your logic accordingly, consistent with what is returned.

Code:
 b := t.ReadString('Section', 'Ident', 'Default');
 if b = 'Default' then
   begin
      PageControl1.Pages[4].TabVisible :=True; 
      PageControl1.TabIndex :=4; 
      btnSave.Enabled :=True;
    end 
 else
   begin
     PageControl1.TabIndex :=0; 
     PageControl1.Pages[4].TabVisible :=False;
   end;
(I also corrected what seems like an obvious logic error.)
Reply With Quote
  #3  
Old 09-13-2010, 11:59 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

I have an idea, use the debugger and see where it passes...
Reply With Quote
  #4  
Old 09-13-2010, 01:31 PM
Shaun Hand Shaun Hand is offline
Junior Member
 
Join Date: Aug 2010
Posts: 24
Default

[QUOTE=Glenn1234;212686]

Code:
 b := t.ReadString('Section', 'Ident', 'Default');
 if b = 'Default' then
   begin
      PageControl1.Pages[4].TabVisible :=True; 
      PageControl1.TabIndex :=4; 
      btnSave.Enabled :=True;
    end 
 else
   begin
     PageControl1.TabIndex :=0; 
     PageControl1.Pages[4].TabVisible :=False;
   end;
QUOTE]
Yes quite definately I'm using TiniFile.
I can write to it, read from it, and populate fields, except when trying to use the tabs visible true/false. I tried to implement what you've suggested, slightly modified, but I don't get it.
Let me provide the code again... with changes, and I think the complete stuff up.

Code:
procedure TForm1.ReadINIExecute(Sender: TObject);
var
  ini: TIniFile;
 begin
  // Create INI Object and open or create file test.ini
     ini := TIniFile.Create(GetSpecialFolderPath($001a)+'\UTCT\UTCT.ini');
  try
   begin
     // Read String value from the INI file.
   Edit7.Text := ini.ReadString ('Setup', 'Tel1', '' );
   Edit8.Text := ini.ReadString ('Setup', 'Tel2', '0800123456' );
// Read Integer value from the INI file.
   x := ini.ReadInteger('Setup', 'Section', 0 );
// Read boolean value from the INI file.
   if ini.ReadBool('Setup', 'Preferred', False)
   then RadioButton1.Checked:= True; Edit7.Enabled :=True;
   if ini.ReadBool('Setup', 'ABC0', False)
   then CheckBox8.Checked:= True;
   if ini.ReadBool('Setup', 'ABC1', False)
   then CheckBox9.Checked:= True;
   if ini.ReadBool('Setup', 'ABC2', False)
   then CheckBox10.Checked:= True;
   if ini.ReadBool('Setup', 'ABC3', False)
   then CheckBox11.Checked:= True;
   if ini.ReadBool('Setup', 'ABC4, False)
   then CheckBox12.Checked:= True;
   if ini.ReadBool('Setup', 'ABC5', False)
   then CheckBox13.Checked:= True;
   if ini.ReadBool('Setup', 'ABC6', False)
   then CheckBox14.Checked:= True;
   if ini.ReadBool('Setup', 'ABC7', False)
   then CheckBox15.Checked:= True;
   if ini.ReadBool('Setup', 'ABC8', False)
   then CheckBox16.Checked:= True;
   if ini.ReadBool('Setup', 'ABC9', False)
   then CheckBox17.Checked:= True;
   if ini.ReadBool('Setup', 'ABC10', False)
   then CheckBox18.Checked:= True;
   if ini.ReadBool('Setup', 'ABC11', False)
   then CheckBox19.Checked:= True;
   if ini.ReadBool('Setup', 'ABC12', False)
   then CheckBox20.Checked:= True;
// Read String value from the INI file.
if not 
 ini.ReadString('Setup', 'Exist', 'True')
  then begin
      PageControl1.Pages[4].TabVisible :=True;
      PageControl1.TabIndex :=4;
      btnSave.Enabled :=True;
end else
    PageControl1.TabIndex :=0;
    PageControl1.Pages[4].TabVisible :=False;
 end;
 finally end;
    ini.Free;
  end;
Now an error occurs @ then begin
PageControl1.Pages[4].TabVisible :=True;


Am I missing something here?
Reply With Quote
  #5  
Old 09-13-2010, 01:36 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

And again someone is bypassing my very good reply:
Quote:
I have an idea, use the debugger and see where it passes
It's the best thing you've ever seen, learn how to use it... Instead of us solving these straight forward issues solve them yourself in 5 minutes (yes, and even faster if you know how to use it)... Saves you so much time...

But probably this wasn't the answer you're hoping for and therefor you bypassed it...

And once you're at it, give your components proper names... what is CheckBox15 do???
Tell me in 6 months without looking at your form... This will take you so much time figuring this all out again...
Reply With Quote
  #6  
Old 09-13-2010, 01:46 PM
Shaun Hand Shaun Hand is offline
Junior Member
 
Join Date: Aug 2010
Posts: 24
Default

Quote:
Originally Posted by Norrit View Post
And again someone is bypassing my very good reply:


It's the best thing you've ever seen, learn how to use it... Instead of us solving these straight forward issues solve them yourself in 5 minutes (yes, and even faster if you know how to use it)... Saves you so much time...

But probably this wasn't the answer you're hoping for and therefor you bypassed it...

And once you're at it, give your components proper names... what is CheckBox15 do???
Tell me in 6 months without looking at your form... This will take you so much time figuring this all out again...
Hi Norrit, If I knew how the debugger worked I would gladly use it. (Where would I get info on how to use it?)
The CheckBox's are a bunch of options which relate to tabs with specific fields and EditBox's, which basicly there is a setup tab, which is my one problem, which by selecting the specific checkbox's will either enable or disable/hide the tabs. ( They are being renamed to cbDoesSomething)
Select the one's that are applicable to you, and save.
The next time you open it, it will display only what you've selected in your preferences/config.
I can get the tab to show by assigning the funtion to a menu item, so that's sorted. But to have it display if no ini file exists is a problem.

Most of the funtions I have been able to get to work, by trawling the forums and looking up what I can't find in books, or asking hopefully good natured people on this forum for assistance.

S
Reply With Quote
  #7  
Old 09-13-2010, 02:46 PM
Glenn1234 Glenn1234 is offline
Senior Member
 
Join Date: Aug 2009
Posts: 131
Default

People indeed seem to have a habit lately of bypassing replies, Norrit. It seems to be a reoccurring thing.

Quote:
Originally Posted by Shaun Hand View Post
Yes quite definately I'm using TiniFile.

Am I missing something here?
1) Evidently you aren't using TIniFile, or are using a substantially different version (i.e. NOT Delphi), because the ValueExists method doesn't exist in anything I have here called TIniFile.

2) When you get presented something, you need to try it EXACTLY as given. Things work the way they work for a reason, and you can't make your mind up that you want to have them work your way when they won't. You are obviously new, in not knowing what a debugger is. In being new, you would do yourself a huge favor to recognize that when people bother to post things in response to you, they are trying to help you and are likely farther along than you in knowledge on these things.
Reply With Quote
  #8  
Old 09-13-2010, 02:59 PM
Shaun Hand Shaun Hand is offline
Junior Member
 
Join Date: Aug 2010
Posts: 24
Default

OK, I've declared TiniFile.
I tried to use ini.WriteString ('Setup', 'Exist', 'True');
and it doesn't do what I want it to. When I use the ini.ValueExists () it reads and does everything I want it to, except make the tab visible and default to it when the ini doesn't exist.

My original source stemmed from http://www.experts-exchange.com/Prog..._20831435.html

It was only when the tabs got involved that it wouldn't work.

Yes I am a noobie, and probably have no idea as to what I'm doing, but would like to learn and be able to learn from people like you.
I have learned a great deal on my own, and from whatever info I can find in books, and tutorials online, but I am stuck here.
Reply With Quote
  #9  
Old 09-13-2010, 04:10 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,333
Default

Well, I want you to learn how to use the debugger rather than give you the solution:
http://delphi.about.com/od/beginners...-debugging.htm
Perhaps taking some of the other beginner courses there wouldn't be a shame aswell...
Reply With Quote
  #10  
Old 09-13-2010, 05:08 PM
Glenn1234 Glenn1234 is offline
Senior Member
 
Join Date: Aug 2009
Posts: 131
Default

Quote:
Originally Posted by Shaun Hand View Post
I have learned a great deal on my own, and from whatever info I can find in books, and tutorials online, but I am stuck here.
Be sure to look at manuals and the online help. They truthfully answer most of the questions if you look at them and follow the directions. Seek to understand how things work and not just copy them (I think that's the problem of a great many on forums these days). Much study always yields great reward, and thinking about what you are doing and have done will help as well (the other stuff you posted this time reveals the problem here).

For example, looking at the documentation for TInifile.ReadString should tell you why I posted what I did. I also indicated you have a logic error, and indicated a solution. Using the debugger will help you see this very readily, which is why Norrit suggested it.
Reply With Quote
Reply

Tags
pagecontrol1, tabindex, visible

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:12 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.