views:

65

answers:

1

I have stored a list of items from gridView into the registry as below:

frmPOSConfigSet.tblCatItems.First;  
while not frmPOSConfigSet.tblCatItems.Eof do
begin  
  RegItemSetting.WriteString('stk Group\Candy',
    frmPOSConfigSet.tblCatItemsCODE.Text,
    frmPOSConfigSet.tblCatItemsSPHOTO.Text);
  frmPOSConfigSet.tblCatItems.Next;  
end;

In Registry Editor, I have this:

stk Group
- Candy
-> YUPI_GUM_HB , c:\Users\chai\Pictures\POS Item Images\image1.jpg
-> YUPI_GUM_SBKISS , c:\Users\chai\Pictures\POS Item Images\image2.jpg

After I close the form and open it again, all values in gridView are gone. How can I retrieve the ident (eg. YUPI_GUM_HB) and its value (eg.c:\Users\chai\Pictures\POS Item Images\image1.jpg) from the registry and put it in the gridView when I load the form?

+2  A: 

It doesn't quite look like you're using TRegistry (too many parameters to WriteString), but if you were, you could use it to get everything back out of the registry. I suspect you're stuck because you want to call ReadString, but you don't know the registry values' names, so you don't know what to pass into ReadString.

You can get a list of all the values' names by calling GetValueNames. Pass it a TStringList (or any other TStrings descendant), and that method will fill the list with all the value names.

var
  Names: TStrings;
  Name, Data: string;
  i: Integer;
begin
  RegItemSetting.OpenKeyReadOnly('stk Group\Candy');
  Names := TStringList.Create;
  try
    RegItemSetting.GetValueNames(Names);
    for i := 0 to Pred(Names.Count) do begin
      Name := Names[i];
      Data := RegItemSetting.ReadString(Name);
    end;
  finally
    Names.Free;
  end;
end;
Rob Kennedy
I don't know what gridView is, so I cannot answer that question. You say the stuff you stored in the registry came from gridView, so how did you get it into gridView in the first place?
Rob Kennedy
Thx for ur help, Rob. i get it already.
i stored and retrieve data from gridView to registry through the dataset.
So it's a data-aware grid control? Then, to get it into the grid, put the stuff into a dataset. I have no idea how to do that.
Rob Kennedy
The gridView is TwwwDBGrid and the dataset is TClientDataSet, it link with each other. So when i append the data to dataset, it will automatic show the data in gridView.