9
9861
Unregistered / Unconfirmed
GUEST, unregistred user!
老是出错:Resource TMyGrid not found.
============================================================
unit ChenwBox;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,DBGrids, DB, Buttons;
type
TChenWCombobox = class;
//TMyGrid=class(TDBGrid) 如果改成这句这没错.
TMyGrid=class(TForm)
private
FMyGrid:TChenWCombobox;
procedure CreateParams(var params:TCreateParams);override;
procedure WMSetFocus(var Msg:TWMSetFocus);message WM_SETFOCUS;
public
constructor Create(AOwner:TComponent);override;
end;
TChenWCombobox = class(TComboBox)
private
FMyForm:TMyGrid;
FSpeedButton : TSpeedButton;
FDowned:Boolean;
FFlag:Boolean;
procedure ShowCombobox;
procedure HideComboBox;
procedure CMCancelMode(var Msg:TCMCancelMode);message CM_CANCELMODE;
procedure WM_LButtonDown(var Msg:TWMMouse);message WM_LBUTTONDOWN;
public
Constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DevTools', [TChenWCombobox]);
end;
{ TChenWCombobox }
procedure TChenWCombobox.CMCancelMode(var Msg: TCMCancelMode);
begin
inherited;
if FDowned then
begin
HideComboBox;
end;
end;
constructor TChenWCombobox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMyForm:=TMyGrid.Create(self);
FDowned:=false;
//以下按钮在Creat时显不出来,也很奇怪.
FSpeedButton := TSpeedButton.Create(Self);
FSpeedButton.Left := FMyForm.Width;
FSpeedButton.Height := 19; // two less than TEdit's Height
FSpeedButton.Width := 19;
FSpeedButton.Caption := '...';
FSpeedButton.Parent := Self;
end;
destructor TChenWCombobox.Destroy;
begin
FMyForm.Free;
FMyForm:=nil;
inherited Destroy;
end;
procedure TChenWCombobox.HideComboBox;
begin
ShowWindow(FMyForm.handle,SW_HIDE);
FDowned:=not FDowned;
end;
procedure TChenWCombobox.ShowCombobox;
var
Point:TPoint;
begin
Point.x:=Left;
Point.y:=top+Height;
Point:=Parent.ClienttoScreen(Point);
SetWindowPos(FMyForm.Handle,HWND_TOP,Point.x,Point.y,0,0,SWP_NOACTIVATE or SWP_HideWindow or SWP_NOSIZE); ShowWindow(FMyForm.Handle,SW_SHOW);
FDowned:=not FDowned;
end;
procedure TChenWCombobox.WM_LButtonDown(var Msg: TWMMouse);
begin
if not FDowned then
begin
ShowComboBox;
end
else
begin
HideCombobox;
end;
end;
{ TMyGrid }
constructor TMyGrid.Create(AOwner: TComponent);
begin
inherited Create(AOwner); // 就是执行到这句后出错.why??
FMyGrid:=TChenWCombobox(AOwner);
ControlStyle:=ControlStyle + [csNoDesignVisible, csReplicatable,
csAcceptsControls];
Width:=150;
Height:=130;
Visible := False;
Parent:=TWinControl(AOwner);
end;
procedure TMyGrid.CreateParams(var params: TCreateParams);
begin
inherited CreateParams(params);
with Params do
begin
Style:=style or ws_popup;
EXStyle:=EXStyle or WS_EX_CLIENTEDGE or WS_EX_TOOLWINDOW;
end;
end;
procedure TMyGrid.WMSetFocus(var Msg: TWMSetFocus);
begin
Inherited;
FMyGrid.SetFocus;
end;
end.
============================================================
unit ChenwBox;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,DBGrids, DB, Buttons;
type
TChenWCombobox = class;
//TMyGrid=class(TDBGrid) 如果改成这句这没错.
TMyGrid=class(TForm)
private
FMyGrid:TChenWCombobox;
procedure CreateParams(var params:TCreateParams);override;
procedure WMSetFocus(var Msg:TWMSetFocus);message WM_SETFOCUS;
public
constructor Create(AOwner:TComponent);override;
end;
TChenWCombobox = class(TComboBox)
private
FMyForm:TMyGrid;
FSpeedButton : TSpeedButton;
FDowned:Boolean;
FFlag:Boolean;
procedure ShowCombobox;
procedure HideComboBox;
procedure CMCancelMode(var Msg:TCMCancelMode);message CM_CANCELMODE;
procedure WM_LButtonDown(var Msg:TWMMouse);message WM_LBUTTONDOWN;
public
Constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('DevTools', [TChenWCombobox]);
end;
{ TChenWCombobox }
procedure TChenWCombobox.CMCancelMode(var Msg: TCMCancelMode);
begin
inherited;
if FDowned then
begin
HideComboBox;
end;
end;
constructor TChenWCombobox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FMyForm:=TMyGrid.Create(self);
FDowned:=false;
//以下按钮在Creat时显不出来,也很奇怪.
FSpeedButton := TSpeedButton.Create(Self);
FSpeedButton.Left := FMyForm.Width;
FSpeedButton.Height := 19; // two less than TEdit's Height
FSpeedButton.Width := 19;
FSpeedButton.Caption := '...';
FSpeedButton.Parent := Self;
end;
destructor TChenWCombobox.Destroy;
begin
FMyForm.Free;
FMyForm:=nil;
inherited Destroy;
end;
procedure TChenWCombobox.HideComboBox;
begin
ShowWindow(FMyForm.handle,SW_HIDE);
FDowned:=not FDowned;
end;
procedure TChenWCombobox.ShowCombobox;
var
Point:TPoint;
begin
Point.x:=Left;
Point.y:=top+Height;
Point:=Parent.ClienttoScreen(Point);
SetWindowPos(FMyForm.Handle,HWND_TOP,Point.x,Point.y,0,0,SWP_NOACTIVATE or SWP_HideWindow or SWP_NOSIZE); ShowWindow(FMyForm.Handle,SW_SHOW);
FDowned:=not FDowned;
end;
procedure TChenWCombobox.WM_LButtonDown(var Msg: TWMMouse);
begin
if not FDowned then
begin
ShowComboBox;
end
else
begin
HideCombobox;
end;
end;
{ TMyGrid }
constructor TMyGrid.Create(AOwner: TComponent);
begin
inherited Create(AOwner); // 就是执行到这句后出错.why??
FMyGrid:=TChenWCombobox(AOwner);
ControlStyle:=ControlStyle + [csNoDesignVisible, csReplicatable,
csAcceptsControls];
Width:=150;
Height:=130;
Visible := False;
Parent:=TWinControl(AOwner);
end;
procedure TMyGrid.CreateParams(var params: TCreateParams);
begin
inherited CreateParams(params);
with Params do
begin
Style:=style or ws_popup;
EXStyle:=EXStyle or WS_EX_CLIENTEDGE or WS_EX_TOOLWINDOW;
end;
end;
procedure TMyGrid.WMSetFocus(var Msg: TWMSetFocus);
begin
Inherited;
FMyGrid.SetFocus;
end;
end.