Here's an update to what I got so far
Textboxes save and retreave perfectly. Success there.
Comboboxes is something else.
Everything seems to save ok. The ini file generated looks pretty perfect
and clean and well layed out. Here is how it's stored in the INI:
: [ComboBox1]
: Values="100 - movies","200 - trips"
: Selected=200 - trips
: Sorted=0
: [ComboBox2]
: Values="1 - Value","2 - Value"
: Selected=1 - Value
: Sorted=0
Here's the messy part.
After the data is retreaved, the dropdown is suppose to show the
following, inside the combobox1:
100 - movies
200 - trips
But, instead, when I retreave this data back, the comboboxs are garbled.
When I click on the dropdown, (and as an example) this is what ends up
showing in the combobox1 list:
100
-
movies"
200 - trip
Note, that Combobox2 is the same problem. And, notice how the last
item in the list (ie, 200 - trip) is missing it's final chars.
The "S" got cut off.
Other than that, the code works perfect! Thank you again.
So far, I need to do some things:
1, fix the combobox problems,
2, create an INI for checkbox controls (not implemented yet), and
3, add in a feature to ADD new items to the list in comboboxs
and SAVE them.
Much help is appreciated. Thanks again.
-mydelphi
The last item to add to the ini file is the checkboxes controls.
: I've got some news.
:
: Finally. After countless what ifs, I got something working. But, I have
: another issue. I can't get it to Load bACK into my controls. I need
: help with this. anyway, here is what I got so far, and it works as far
: as I can tell, when I, at the DOS prompt c:\type ctrldef.ini, it will
: display a bunch of settings and things.
: [i]I've simplyied it a little ie, t:=tonc... etc. less typing.[/i]
:
:
: // write out the data
: t:=tcontrolsFile.Create('h:\ctrldef.ini');
: t.SaveControls(form1);
:
:
:
: So, I've made some more progress. great.
:
: Now, I did notice something. my combobox has some funny char in it or
: will mess up my original values when I try and load it with the Saved
: ctrldef.ini contents:
:
:
: // read in the data
: t:=tcontrolsFile.Create('h:\ctrldef.ini');
: t.LoadControls(form1);
:
:
: Now, as I was saying, the controls aren't properly loading back. I need
: some help with this. If anyone else would like ta help, plase do so.
: I'd really appreciate it

:
: I am worried about one more thing though. How to I ADD to my combobox
: list of items ?
: I'm going to be doing this, using a separate Textbox (blank by default,
: until user enters somerthing into it, and a NEW item should be added to
: the list when user clicks on the Save button (or SaveTemplate button)
:
: Thanks again.
: -mydelphi
:
:
:
: : : Hi,
: : :
: : : I'm looking for some suggestions.
: : :
: : : I've pretty much exhausted myself of a theral search in all of my
: : : libraries of books for any example or hints or whatever,
: : :
: : : Mastering Delphi 3
: : : Secrets of Delphi 2
: : : Delphi 3 Super Bible
: : : And several other books
: : : Plus, the Internet (doing actual web searches)
: : :
: : : So, here I am, asking some more questions.
: : :
: : : Ok then, I have, yet another problem. I'm trying to STORE my controls
: : : values into a file. I've mimiced ONLY the controls values/property
: : : that I will end up using.
: : :
: : : I've thought about using the TIniFle unit and save to and INI file,
: : : and this would be simple, if all I was doing was saying ONE dementional
: : : strings, Intergers, even checkbox values ie, .checked=boolean,
: : : but that turned out to be a bad idea. If I have a combobox for instance,
: : : with a list of items, say 15 of them, how am I going to store them in this
: : : INI file structure, and then put them back into the combobox later, and
: : : I go to retreave the complete file (control structure on my form)
: : :
: : : I would love to just store the ALL the controls AND their values from my
: : : form, and just recall them as they were last set, but after trying that,
: : : using a file structure below, either my system would crash or I did not
: : : get back my values (they did not get stored?)
: : :
: : :
Example:
: : :
: : :
: : : Type
: : : TmyControls = record
: : : txtTmpListLastStr: String[100]; // last highlisted string
: : : cbTmpList: TCombobox;
: : : chbYesNo: TCheckbox;
: : : txtSize: Integer;
: : : end;
: : :
: : : var
: : : F : file of TmyControls;
: : : myControlsRecStruc: TmyControls;
: : : .
: : : .
: : : myControlsRecStruc.txtTmpListLastStr := form1.txtTmpListLastStr;
: : : myControlsRecStruc.cbTmpList := form1.cbTmpList.checked;
: : : myControlsRecStruc.chbYesNo := form1.chbYesNo;
: : : myControlsRecStruc.txtSize := form1.txtSize;
: : : .
: : : .
: : : // Write the data to our file structure
: : : assign(f,'h:\ctrldef.ini');
: : : rewrite(f);
: : : write(f,myControlsRecStruc);
: : : close(f);
: : :
: : : // Read the data back, from our file structure, into our Controls
: : : assign(f,'h:\def.ini');
: : : reset(f);
: : : read(f,myControlsRecStruc);
: : : close(f);
: : : .
: : : .
: : : // populate our Controls from file structure here.
: : : .
: : : .
: : :
: : :
: : : Not to forget that all the above are Controls on my form.
: : :
: : : but the above presents too many problems:
: : : 1 - combobox: If I add a new item (which I will) how to they get inserted
: : : and properly sorted. If I have a mechanism for storing the last position
: : : or selection in the combobox, and I go and insert a new item into this
: : : list, won't I throw off the order AND the new item ?
: : : 2 - some of my controls are mixed values. Example, there are some
: : : Intergers, Strings (only works if I say String[nnn], NOT String) and
: : : checkboxes. I use/store the chbYesNo.checked values.
: : :
: : : I'm sorry for being so lenghthy, but it was difficult to explain.
: : : I was sure I read somewhere's in one of my Books on how to do this, but I
: : : could not find anything in my latest search.
: : :
: : : I really hope that it's something very simple that I over looked

: : :
: : : Thank you for any suggestions

: : :
: : : -mydelphi
: : :
: : Saving the controls into an inifile is a smart idea, since you can create a single section to hold all the values you want for a single control. The easiest way to code this is to create a descendant of a TIniFile or TMemIniFile, which adds several new methods to handle certain classes of controls. Here is an example in code.
: :
: : type
: : TControlsFile = class(TIniFile)
: : private
: : procedure LoadComboBox(Control: TComboBox);
: : procedure SaveComboBox(Control: TComboBox);
: : procedure LoadEdit(Control: TEdit);
: : procedure SaveEdit(Control: TEdit);
: : public
: : procedure LoadControls(Form: TForm);
: : procedure SaveControls(Form: TForm);
: : end;
: :
: : procedure TControlsFile.LoadComboBox(Control: TComboBox);
: : begin
: : with Control do begin
: : // first read if the list is sorted
: : Sorted := ReadBool(Name, 'Sorted', true);
: : // read all the items, which are automatically sorted (if sorted = true)
: : Items.CommaText := ReadString(Name, 'Values', 'DefaultValues');
: : // read the selected item
: : ItemIndex := Items.IndexOf(ReadString(Name, 'Selected', ''));
: : // add more properties as you like, by calling the correct ReadXXXX method
: : end;
: : end;
: :
: : procedure TControlsFile.LoadControls(Form: TForm);
: : var
: : i: integer;
: : begin
: : with Form do
: : if ComponentCount > 0 then
: : // loop through all the components on the form and
: : for i := 0 to ComponentCount-1 do
: : // and call the load routine for its class
: : if Components[i] is TComboBox then
: : LoadComboBox(Components[i] as TComboBox)
: : else if Components[i] is TEdit then
: : LoadEdit(Components[i] as TEdit);
: : // Add more control types by adding more "else-if-then"s
: : end;
: :
: : procedure TControlsFile.LoadEdit(Control: TEdit);
: : var
: : s: string;
: : begin
: : with Control do begin
: : // read the text
: : Text := ReadString(Name, 'Text', 'Some default text');
: : // read the font string
: : s := ReadString(Name, 'Font', 'MS Sans Serif@8@----@0@');
: : // set the font properties based on the font string
: : Font.Name := Copy(s, 1, Pos('@', s)-1);
: : Delete(s, 1, Pos('@', s));
: : Font.Size := StrToInt(Copy(s, 1, Pos('@', s)-1));
: : Delete(s, 1, Pos('@', s));
: : Font.Style := [];
: : if s[1] = '+' then
: : Font.Style := Font.Style + [fsBold];
: : if s[2] = '+' then
: : Font.Style := Font.Style + [fsItalic];
: : if s[3] = '+' then
: : Font.Style := Font.Style + [fsUnderline];
: : if s[4] = '+' then
: : Font.Style := Font.Style + [fsStrikeOut];
: : Delete(s, 1, Pos('@', s));
: : Font.Color := StrToInt(Copy(s, 1, Pos('@', s)-1));
: : end;
: : end;
: :
: : procedure TControlsFile.SaveComboBox(Control: TComboBox);
: : begin
: : with Control do begin
: : // write the properties
: : WriteString(Name, 'Values', Items.CommaText);
: : WriteString(Name, 'Selected', Items[ItemIndex]);
: : WriteBool(Name, 'Sorted', Sorted);
: : // add more properties as you like, by calling the correct WriteXXXX method
: : end;
: : end;
: :
: : procedure TControlsFile.SaveControls(Form: TForm);
: : var
: : i: integer;
: : begin
: : with Form do
: : if ComponentCount > 0 then
: : // loop through all the components on the form and
: : for i := 0 to ComponentCount-1 do
: : // and call the save routine for its class
: : if Components[i] is TComboBox then
: : SaveComboBox(Components[i] as TComboBox)
: : else if Components[i] is TEdit then
: : SaveEdit(Components[i] as TEdit);
: : // Add more control types by adding more "else-if-then"s
: : end;
: :
: : procedure TControlsFile.SaveEdit(Control: TEdit);
: : var
: : s: string;
: : begin
: : with Control do begin
: : // write the text
: : WriteString(Name, 'Text', Text);
: : // copy the font properties into a single string
: : s := '----'; // assume normal style
: : if fsBold in Font.Style then // if style is bolded then
: : s[1] := '+'; // change the value in the string
: : if fsItalic in Font.Style then // same with italic
: : s[2] := '+';
: : if fsUnderline in Font.Style then
: : s[3] := '+';
: : if fsStrikeOut in Font.Style then
: : s[4] := '+';
: : // compile the complete font string
: : s := Format('%s@%d@%s@%d@', [Font.Name, Font.Size, s, Integer(Font.Color)]);
: : // write that string
: : WriteString(Name, 'Font', s);
: : end;
: : end;
: :
: : This example will save and load the properties of all the TComboBoxes and TEdits on a single form. The format of the resulting file will be something like this:
: :
: : [Edit1]
: : Text=Here is the line typed into edit1
: : Font=Arial@8@+---@0@
: :
: : [Edit2]
: : Text=Here is the line typed into edit2
: : Font=MS Sans Serif@8@----@0@
: :
: : [ComboBox1]
: : Values="Value 1","Value 2","Value 4","Value 3"
: : Selected=Value 3
: : Sorted=false
: :
: : This example file should fill the Edit1 with a bold Arial 8 pt. text, while Edit2 has a normal MS Sans Serif 8 pt. text.
: :
: : This example should give you an idea, of how to save the properties of every control you wish. Sometimes you can take a small shortcut in the coding of the load/save routine. If you don't want to save the fonts of your editboxes, you could use the TCustomEdit for your load/save routines. This will then also be used to save all edits and memos.
: :
: :
:
: