关于保存当前窗体的问题(100)

  • 主题发起人 主题发起人 Chenjinan
  • 开始时间 开始时间
C

Chenjinan

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,下午好,我想实现一个这样的功能,在主窗体上放一个TToolButton控件,用来保存当前登录用户对子窗体的风格.代码如下:procedure TfrmMain.cmdSaveFormClick(Sender: TObject);var oComp: TComponent; i:integer;begin for i:=MDIChildCount-2 downto 0 do if MDIChildren.Caption =tabTask.Tabs[tabTask.TabIndex] then begin oComp :=MDIChildren.FindComponent('StoreForm1'); if oComp<>nil then TFormStore(oComp).SaveFormPlacement; end;end;现在碰到一难题,当我按下这按钮时,不单是当前登录用户的风格被保存(当然这是我想要的),而且其它所有的用户也跟着被保存此时同样的界面风格(这不是我想要的).请高手指点下,谢谢!
 
在线等待哟,那们好心人帮下哟
 
怎么没人帮一下呢,如果觉得说得不清楚,可以提出来嘛
 
TFormStore是个什么东西?既然保存一个用户的风格那应该把保存的风格内容存到当前用户相关的位置上下次这个用户登录时读取相关的风格从你的代码上没看到任何保存与当前用户的关系,仅仅是保存了风格,所以任何用户登录都会是这个保存的风格
 
谢谢你的指点,他是自己写的一个控件
 
我自己也来一边找找
 
unit FormStore;interfaceuses PropRW, dbtables, menus,db,extctrls, Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type TFormStore = class(TComponent) private { Private declarations } FStoredProps :TStrings; FStorePropValues :string; FPopupMenu :TPopupMenu; FDatabaseName :string; FQryStorage :TQuery; FSaveFormCreate: TNotifyEvent; FSaveWindowProc: TWndMethod; FBeforeSave: TNotifyEvent; procedure LoadPropValues(Reader: TReader); procedure StorePropValues(Writer: TWriter); procedure SetStoredProps(Value: TStrings); procedure SetEvents; procedure FormCreate(Sender: TObject); procedure FormWindowProc(var Message: TMessage); function GetForm: TCustomForm; procedure OnMenuSaveClick(Sender: TObject); procedure OnMenuClearClick(Sender: TObject); function GetHasSaved() :Boolean; protected procedure Loaded; override; procedure DefineProperties(Filer: TFiler); override; { Protected declarations } public { Public declarations } constructor Create(AOwner: TComponent); override; destructor Destroy; override; procedure SaveFormPlacement; procedure ClearFormPlacement; procedure RestoreFormPlacement; property HasSaved :Boolean read GetHasSaved; published { Published declarations } property StoredProps: TStrings read FStoredProps write SetStoredProps; property DatabaseName: string read FDatabaseName write FDatabaseName; property BeforeSave :TNotifyEvent read FBeforeSave write FBeforeSave; end; var lCanStoreForm :Boolean = True; procedure Register;implementationprocedure Register;begin RegisterComponents('SelfControl', [TFormStore]);end;constructor TFormStore.Create(AOwner: TComponent);begin inherited Create(AOwner); FStoredProps :=TStringList.Create; FPopupMenu :=nil; FQryStorage :=nil; FDatabaseName :='';end;destructor TFormStore.Destroy;begin FStoredProps.Free; if Assigned(FPopupMenu) then FPopupMenu.Free; if Assigned(FQryStorage) then FQryStorage.Free; inherited Destroy;end;procedure TFormStore.FormWindowProc(var Message: TMessage);begin if Message.Msg =WM_SYSCOMMAND then case Message.WParam of 30007: OnMenuSaveClick(nil); 30008: OnMenuClearClick(nil); end; if Assigned(FSaveWindowProc) then FSaveWindowProc(Message);end;procedure TFormStore.SetEvents;begin if Owner is TCustomForm then begin with TForm(Owner) do begin FSaveFormCreate := OnCreate; OnCreate := FormCreate; end; end;end;procedure TFormStore.LoadPropValues(Reader: TReader);begin FStorePropValues :=Reader.ReadString;// if Reader.ReadBoolean then// MyCompProperty := Reader.ReadComponent(nil);end;procedure TFormStore.StorePropValues(Writer: TWriter);var i :Integer; ts,sCompName,sPropName :string; tsStream :TStringStream; toWriter :TPropWriter;begin tsStream :=TStringStream.Create(''); try toWriter :=TPropWriter.Create(tsStream, 4096); try for i :=0 to FStoredProps.Count -1 do begin ts :=FStoredProps; sCompName :=Copy(ts, 1, Pos('.', ts)-1); sPropName :=Copy(ts, Pos('.', ts)+1, 2000); toWriter.WritePropAll(GetForm().FindComponent(sCompName), sPropName); end; toWriter.WriteListEnd; finally toWriter.Free; end; tsStream.Seek(0, soFromBeginning); FStorePropValues :=tsStream.DataString; finally tsStream.Free; end; Writer.WriteString(FStorePropValues);end;procedure TFormStore.DefineProperties(Filer: TFiler);begin inherited; { allow base classes to define properties } //Filer.DefineProperty('PropValues', LoadPropValues, StorePropValues, True);end;procedure TFormStore.SaveFormPlacement;var oStream :TBlobStream; oWriter :TPropWriter; i : Integer; ts,sCompName,sPropName :string; oFieldStorage :TBlobField;begin if not lCanStoreForm then Exit; //无权限用户禁止修改设置 with FQryStorage do begin Close; Open; if IsEmpty then begin Append; FQryStorage.FieldByName('FormClass').AsString :=GetForm().ClassName; FQryStorage.FieldByName('CzyCode').AsString :='mazhen'; Post; Edit; end else Edit; end; oFieldStorage :=(FQryStorage.FieldByName('FormStorage') as TBlobField); oFieldStorage.Clear; oStream :=TBlobStream.Create(oFieldStorage, bmReadWrite); try oWriter :=TPropWriter.Create(oStream, 4096); try oStream.Seek(0, soFromBeginning); oWriter.WriteInteger(FStoredProps.Count); for i :=0 to FStoredProps.Count -1 do begin ts :=FStoredProps; sCompName :=Copy(ts, 1, Pos('.', ts)-1); sPropName :=Copy(ts, Pos('.', ts)+1, 2000); oWriter.WritePropAll(GetForm().FindComponent(sCompName), sPropName); end; oWriter.WriteListEnd; finally oWriter.Free; end; finally oStream.Free; end; //FQryStorage.FieldByName('PropCount').AsInteger :=FStoredProps.Count; FQryStorage.Post;end;procedure TFormStore.RestoreFormPlacement;var oStream :TBlobStream; oReader :TPropReader; oFieldStorage :TBlobField;begin with FQryStorage do begin Close; Open; end; if FQryStorage.IsEmpty then Exit; oFieldStorage :=(FQryStorage.FieldByName('FormStorage') as TBlobField); if oFieldStorage.IsNull then Exit; oStream :=TBlobStream.Create(oFieldStorage, bmRead); try oReader :=TPropReader.Create(oStream, oStream.Size); try oStream.Seek(0, soFromBeginning); oReader.ReadProps(Self.Owner, 0); //,FQryStorage.FieldByName('PropCount').AsInteger); finally oReader.Free; end; finally oStream.Free; end;end;procedure TFormStore.Loaded;var Loading: Boolean;begin Loading := csLoading in ComponentState; inherited Loaded; if not (csDesigning in ComponentState) then begin if Loading then SetEvents; end;end;function TFormStore.GetForm: TCustomForm;begin Result := (Owner as TCustomForm);end;function TFormStore.GetHasSaved: Boolean;begin Result := not(FQryStorage.IsEmpty);end;procedure TFormStore.SetStoredProps(Value: TStrings);begin FStoredProps.Assign(Value);end;procedure TFormStore.FormCreate(Sender: TObject);var hSysMenu :HMENU;begin hSysMenu :=GetSystemMenu(GetForm().Handle, False); AppendMenu(hSysMenu,MF_SEPARATOR, 0,nil); AppendMenu(hSysMenu,MF_STRING,30007, '保存当前窗口设置(&B)'); if not lCanStoreForm then //无权限用户禁止修改设置 EnableMenuItem(hSysMenu,30007,MF_GRAYED); AppendMenu(hSysMenu,MF_STRING,30008, '清除当前窗口设置(&Q)'); with GetForm() do begin FSaveWindowProc :=WindowProc; WindowProc :=FormWindowProc; end; FQryStorage :=TQuery.Create(Self); FQryStorage.DatabaseName :=FDatabaseName; FQryStorage.SQL.SetText(PChar( Format('SELECT * FROM S_FormStorage WHERE FormClass = ''%s''', [GetForm().ClassName]) )); FQryStorage.RequestLive :=True; try RestoreFormPlacement; if FQryStorage.IsEmpty then EnableMenuItem(hSysMenu,30008,MF_GRAYED); except Application.MessageBox('窗口设置错误! 请清除当前窗口设置' ,'系统错误', MB_ICONERROR); end; if Assigned(FSaveFormCreate) then FSaveFormCreate(Sender);end;procedure TFormStore.OnMenuSaveClick(Sender: TObject);begin if Assigned(FBeforeSave) then FBeforeSave(Self); SaveFormPlacement();end;procedure TFormStore.OnMenuClearClick(Sender: TObject);begin ClearFormPlacement;end;procedure TFormStore.ClearFormPlacement;begin with FQryStorage do begin Close; Open; end; if not FQryStorage.IsEmpty then FQryStorage.Delete;end;end.
 
不知道出错在那,还请大家帮一下忙,非常感谢!
 
問題1你存的時候有沒有存入用戶的信息,問題2讀的時候是不是讀取不同用戶存放的風格信息~~~~~~~關鍵是你有沒有區分不同用戶存放的不同的風格信息~~~~
 
自己找找,解決掉這兩個問題,就ok 了!
 
你一個 TFormStore(oComp).SaveFormPlacement; 這樣存,根本都沒有不同用戶的信息寫進去,那你再讀出來的時候怎么區分呢~~~~~~~
 
再看了一下你貼出來的代碼SaveFormPlacement 函數裡面根本都沒有不同的用戶信息寫進去RestoreFormPlacement 函數裡面也沒有不同的用戶信息讀出來那你怎么區分不同用戶的設置呢~~~~自己修改一下吧很好解決的~~~
 
DatabaseName你指定了?TPropReader、TPropWriter是什么?看代码,好像你为每个用户分配一个不同的DatabaseName就行
 
是否可以用ini文件呢?
 
谢谢大家,上次忙着,都没有空进来,再次谢谢大家,顺便给大家拜年,祝大家牛年吉祥,事业牛,财气牛,身体更牛!我回家看了一个代码,找出问题来了,谢谢!!!!
 
手上现在又碰到一个问题,现在都没好意思问了,还是自己找找先吧!实在找不出的时候,再向大伙请教
 
招聘启示本公司是一家大型的信息专业网站,公司09年为了开拓全国业务需要,现急需招聘具备良好的团队合作精神,责任感强,善于沟通,能够承受压力的程序员3-5名,职位要求如下:(一)Delphi程序员1、三年以上Delphi开发经验,精通Delphi+SQL Server编程, 熟悉SQ LServer数据库;2、从事过行业管理信息系统开发全过程,具有一定的软件工程思想;3、有电子商务、国际货运代理、仓储、物流EDICRM软件开发经验优。(二)C#程序员1.二年以上C#软件研发工作经验;2.有软件体系结构设计经验,有很强的C#编码技能;3.精通XML、MSDTC、COM+/COM、Web Services和.net framework;4.熟练掌握Oracle、SQL Server等大型数据库系统,熟悉数据库设计、调优及SQL存储过程的编写。(三)网站设计程序员1. 美术、计算机二年以上工作经验;2. 熟悉SQL数据,精通ASP.NET编程进行后台的开发,有一定的编辑经验,能够独立完成项目方案的设计;3. 精通网页设计和平面设计的相关软件,如Dreamweaver、Photoshop、Flash、Coredraw等 ;4.文字功底好,有丰富的想象策划能力,能独立完成大型网站的建设需求/策划方案。 工作地点:河南 工作方式:全职 福利待遇:面议(不会低于你的期望值)联系方式:冯先生 13603728111
 
接受答案了.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
738
SUNSTONE的Delphi笔记
S
S
回复
0
查看
730
SUNSTONE的Delphi笔记
S
S
回复
0
查看
816
SUNSTONE的Delphi笔记
S
后退
顶部