Hi How can i save the current state of Ribbon So that i can load ribbon with the same state while opening the exe next time using Delphi?
You could use Windows Registry to save state of Ribbon when application closes, and then restore when opening Application.
This is code for work with Registries:
function LoadStringFromRegistry(sKey, sItem,
sDefVal: string; RootKey : HKEY = HKEY_CURRENT_USER): string;
var
Reg : TRegistry;
begin
Reg := TRegistry.Create(KEY_READ); // REMOVE
try
Reg.RootKey := RootKey;
if Reg.OpenKey(sKey, false) then
begin
Result:=Reg.ReadString(sItem);
Reg.CloseKey;
end
else
Result:='';
finally
Reg.Free;
end;
end;
procedure SaveStringToRegistry(sKey, sItem, sVal : string; RootKey : HKEY = HKEY_LOCAL_MACHINE);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create(KEY_READ or KEY_WRITE);
try
Reg.RootKey := RootKey;
if Reg.OpenKey(sKey, true) then
begin
reg.WriteString(sItem, sVal);
Reg.CloseKey;
end;
finally
reg.Free;
end;
end;
State Registry in uses list.
Sample:
SaveStringToRegistry('Software\Company\Application', 'Left','20',HKEY_LOCAL_MACHINE);
left := LoadStringFromRegistry('Software\Company\Application', 'Left','',HKEY_LOCAL_MACHINE);
If you want to save state for each individual user of Windows use HKEY_CURREN_USER instead of HKEY_LOCAL_MACHINE.
If your application have other way of user management (Database), save state of Ribbon in database.
I never used the standard Ribbon in Delphi.. but after my comment to @Ljubomir answer, I decided to investigate a bit to help you.
From source code, looking at the way the customize dialog works I discovered Ribbon is tied to TActionManager, which also I never used beforehand. Again, Looking at the source of TCustomActionManager, I noticed the SaveToFile/SaveToStream LoadFromFile/LoadFromStream methods I suppose is the way to save/load the ribbon (action manager) state information.
ON the other hand, the TActionManager have a FileName property. If you set it, it automatically loads and saves the ActionManager state at proper times.
Hope this brings light to you.