Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to TCheckListBox LoadFromFile/SaveToFile Method, included checked state? Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
30-Jun-03
Category
VCL-General
Language
Delphi 2.x
Views
112
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Bjarne Winkler

What to use the TCheckListBox LoadFromFile and SaveToFile Method, and store the 
checked state at the same time?

Answer:

If you embed the Checked property into the actual entry as a “1” or “0” charter you 
can save the file with the normal SaveToFile method. When a file is loaded using 
the LoadFromFile method as normal.  Then extract the first charter from the entry 
and you will have the checked state. 
1   
2   {====================================}
3   
4   procedure TFrameRuleEngine.SaveRules;
5   {====================================}
6   var
7     i: Integer;
8   
9   begin
10    i := 0;
11    while i < CheckListBoxRule.Items.Count do
12    begin
13      if CheckListBoxRule.Items[i] = '' then
14      begin
15        // Delete entry it is empty
16        CheckListBoxRule.Items.Delete(i);
17      end
18      else
19      begin
20        // Add a 1 or 0 as the first charter in the entry for checked or not checked
21        CheckListBoxRule.Items[i] := IntToStr(Integer(CheckListBoxRule.Checked[i])) +
22          CheckListBoxRule.Items[i];
23        Inc(i);
24      end;
25    end;
26    // Save the full list as normal
27    CheckListBoxRule.Items.SaveToFile(ExtractFilePath(Application.ExeName) +
28      'Rule.Txt');
29  end;
30  
31  {===================================}
32  
33  procedure TFrameRuleEngine.LoadRules;
34  {===================================}
35  var
36    sChecked: string;
37    i: Integer;
38  
39  begin
40    if FileExists(ExtractFilePath(Application.ExeName) + 'Rule.Txt') then
41    begin
42      // Read the file as normal
43      CheckListBoxRule.Items.LoadFromFile(ExtractFilePath(Application.ExeName) +
44        'Rule.Txt');
45      i := 0;
46      while i < CheckListBoxRule.Items.Count do
47      begin
48        if CheckListBoxRule.Items[i] = '' then
49        begin
50          // Delete an empty entry
51          CheckListBoxRule.Items.Delete(i);
52        end
53        else
54        begin
55          // Get the checked state
56          sChecked := Copy(CheckListBoxRule.Items[i], 1, 1);
57          CheckListBoxRule.Items[i] := Copy(CheckListBoxRule.Items[i], 2,
58            Length(CheckListBoxRule.Items[i]));
59          // Update the Checked property
60          CheckListBoxRule.Checked[i] := Boolean(StrToInt(sChecked));
61          Inc(i);
62        end;
63      end;
64    end;
65  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC