高手请进(100分)

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

Chenjinan

Unregistered / Unconfirmed
GUEST, unregistred user!
谢谢你的光临,请问下面的语句有错嘛,错在那里,怎样修改,谢谢!
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.FormWindowProc(var Message: TMessage);
begin
if Message.Msg =WM_SYSCOMMAND then
case Message.WParam of
30007: OnMenuSaveClick(nil);
30008: OnMenuClearClick(nil);
end;
inherited;
end;
 
窗体最大化或最小化的消息 Message.Msg =WM_SYSCOMMAND
你这个应该是哪个控件类里定义的吧
单纯贴这一段是没法看出哪错误的
 
这样一改,右下的窗体就弹不出来
 
全部代码是:
unit FormStore;
interface
uses 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;
implementation
procedure 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 -1do
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, soFrombegin
ning);
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 FQryStoragedo
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, soFrombegin
ning);
//oWriter.WriteInteger(FStoredProps.Count);
for i :=0 to FStoredProps.Count -1do
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 FQryStoragedo
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, soFrombegin
ning);
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 FQryStoragedo
begin
Close;
Open;
end;
if not FQryStorage.IsEmpty then
FQryStorage.Delete;
end;

end.
 
可能这句 if Message.Msg = WM_SYSCOMMAND 要改一下,不要用 WM_SYSCOMMAND ?
 
有什么好建议,如果对,分数一次给是肯定的,还诚心的感谢!
 
重载WindowProc出错误了吧?提示的错误消息是什么?
 
好象是地址错误,如果可以的话,我可以用QQ连过去给兄台看看
错误提示"
project HLWE.exe raised exception class EAccessViolation with message'Access violation at address 00414F6C in module HLWE.exe'.Read of address 00000008'.Process stopped.Use Step or Run to continue.
 
呵呵,你这个错误消息说了等于没说,用断点跟踪下
 
用断点跟踪了
提示:
[Hint] FormStore.pas(20);Private symbol"LoadPropValues"declared but never usen
[Hint] FormStore.pas(20);Private symbol"StorePropValues"declared but never usen
 
各位兄台们,急啊,帮帮忙哟!
等着调出来去吃饭呢
 
情况复杂,如果你用的是别人做好的控件的话,应该是调用的问题
别着急,晚上我帮你调试一下,先吃饭去吧,呵呵
 
真的啊,太谢谢了!
我现在还在公司加班呢,一出去,就回不来了,没钥匙哟
兄弟,我等着你!谢谢!
 
我仔细看了下,这个单元主要的功能就是
在退出窗体的时候进行窗体数据的保存或清空,怎么还有数据库的内容呢?
 
对,就是这个功能,这里又不能发图片,如果可以,我还可以发个图片过来给你看看
 
兄台,调试出来了没,嘿嘿!
急哈,老板又在摧啊!
 
已向你申请,谢谢!
 
那位兄台可能还在享受美味的晚餐哈
还有那位好心人可以帮下我哟,调不出来,就没饭吃啊
 
后退
顶部