Subject Re: [IBO] How can I save the TIB_Grid layout
Author Andrew
kstrobel2 wrote:

>After the user modified column widths or column order in a TIB_Grid,
>how can I save the new layout, to the registry so?
>
>
Here's how I did it.
There's probably a better way but this works for me.

Andrew Haines
OPSCON Inc (http://opscon.ca)
"Speed is fine, accuracy is final."




from Form.OnCreate
------------------

User.RestoreState(Self, 'IB_Query1.FieldsIndex', IB_Query1.FieldsIndex);
User.RestoreState(Self, 'IB_Query1.FieldsDisplayWidth',
IB_Query1.FieldsDisplayWidth);


From Form.Close
---------------
User.SaveState(Self, IB_Query1.FieldsIndex, 'IB_Query1.FieldsIndex');
User.SaveState(Self, IB_Query1.FieldsDisplayWidth,
'IB_Query1.FieldsDisplayWidth');


From user.pas
-------------
procedure SaveState(const aForm : TForm; const aItem : TPersistent;
const aKey : String);
var
myStream : TMemoryStream;
Buffer : PChar;
BufSize : Integer;
begin
myStream := TMemoryStream.Create;
MyRegistry.RootKey := HKEY_CURRENT_USER;
MyRegistry.OpenKey('Software\opscon\state\' + aForm.ClassName, True);
try
if (aItem is TComponent) then
begin
myStream.WriteComponent((aItem as TComponent));
myStream.Position := 0;
ShowMessage(aItem.GetNamePath + ' saved as TComponent');
end;
if (aItem is TStrings) then
begin
MyRegistry.WriteString(akey + '.String', (aItem as TStrings).Text);
end;
myStream.Position := 0;

if myStream.Size > 0 then MyRegistry.WriteBinaryData(aKey, myStream,
myStream.Size);
finally
MyRegistry.CloseKey;
myStream.Free;
end;
end;

procedure RestoreState(const aForm : TForm; const aKey : String; aItem :
TPersistent);
var
myStream : TMemoryStream;
BufSize : Integer;
begin
myStream := TMemoryStream.Create;
MyRegistry.RootKey := HKEY_CURRENT_USER;
MyRegistry.OpenKey('Software\opscon\state\' + aForm.ClassName, True);
try
if (aItem is TStrings) then
begin
if MyRegistry.ValueExists(aKey + '.String') then
begin
if (aItem is TStrings) then (aItem as TStrings).Text :=
MyRegistry.ReadString(aKey + '.String');
end;
end;
finally
MyRegistry.CloseKey;
myStream.Free;
end;
end;




[Non-text portions of this message have been removed]